Page 1 of 1

Not passing form Select/options

Posted: Tue Nov 11, 2008 7:22 am
by Lonestarjack
My form has several drop down boxes such as Statecodes, Salutations, etc
It uses the Post method.
All fields are passed with $_POST except the select boxes whether they are changed or not.
Probably some setting in the .ini file, but I am unable to find it.
I am new to PHP after yaers of ColdFusion programming.
Help please.

Re: Not passing form Select/options

Posted: Tue Nov 11, 2008 7:25 am
by Ziq
First of all, post your code with a HTML form

Re: Not passing form Select/options

Posted: Tue Nov 11, 2008 8:07 am
by Lonestarjack
Ziq wrote:First of all, post your code with a HTML form
I would like to post all the code but it is a great deal of space.
There are included javascripts, and ajax coding.
View source will not show the code as it is all generated by ajax.
It forms good HTML code otherwise I would not have it on the display form.

Re: Not passing form Select/options

Posted: Tue Nov 11, 2008 8:20 am
by Ziq
How we can help you if we don't know anything at all?

This isn't php configuration problem. I think problem in HTML (or javascript, or something else) or php script. Are you sure that select boxes don't pass values? Try to print $_POST variable in a handler script

Code: Select all

<?php
print_r($_POST);
?>
Maybe you can show a link on your script?

Re: Not passing form Select/options

Posted: Tue Nov 11, 2008 8:30 am
by aceconcepts
Can you just post you form or just event the select element?

Re: Not passing form Select/options

Posted: Wed Nov 12, 2008 7:32 am
by Lonestarjack
aceconcepts wrote:Can you just post you form or just event the select element?
OK I have reduced the code to a minimum:
Here is the php code--
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>TestSelects.php</title>
</head>
<body>

<P></P>
Test selects to post
<p></p>
<form name="editform" action="testajaxpost.php" method="post">
Record ID:<input name='record_id' value=100 size='4' readonly='Yes'>
<span>Type:</span>
<?php
$type ="B";
echo '<select class="input" name "type" size = "1">';
if($type== 'P'){
echo '<option value="P" selected>Personal</option>';
} else {
echo '<option value="P" >Personal</option>';
};
if($type== 'K'){
echo '<option value="K" selected>Mary Kay</option>';
} else {
echo '<option value="K" >Mary Kay</option>';
};
if($type== 'B'){
echo '<option value="B" selected>Yellow Pages</option>';
} else {
echo '<option value="B" >Yellow Pages</option>';
};
echo "</select>";
?>

<span >Lunch:</span>
<select name 'Lunch' size = '1'>
<option value="Yes" selected>Yes</option>
<option value="No" >No</option>
</select>
<br>
<input type='Submit'>
</form>
</body>
</html>
=======================================
Here are the results of the print_r:
array
'record_id' => string '100' (length=3)

Array ( [record_id] => 100 )
=========================================
Here the results of the code when written in ColdFusion:
array
'record_id' => string '100' (length=3)
'type' => string 'B' (length=1)
'lunch' => string 'Y' (length=1)

Array ( [record_id] => 100 [type] => B [will] => Y )

Re: Not passing form Select/options

Posted: Wed Nov 12, 2008 7:43 am
by Eran
You are missing an equality operator after the 'name' property:

Code: Select all

 
<select class="input" name "type" size = "1">
 
Should be:

Code: Select all

 
<select class="input" name="type" size = "1">
 
Also you might write it more compact like this:

Code: Select all

 
$select = '<select class="input" name="type" size="1">';
$options = array('P' => 'Personal','K' => 'Mary Kay','B' => 'Yellow Pages');
foreach($options as $key => $val) {
     $select .= '<option value="' . $key . '"' . ($key == $type ? ' selected="selected"' : '') . '>' . $val . '</option>';
}
$select .= '</select>';
 
 
This way you can add options without repeating the logic.

Re: Not passing form Select/options

Posted: Wed Nov 12, 2008 8:34 am
by Lonestarjack
A million thanks for your sharp eyes and the code snippet.

I usually use this for query generated dropdowns:

while(list($id, $tblst)=mysql_fetch_row($stresult)) {
if($id == $statecode)
{ $stselected = ' selected'; }else{ $stselected = '';}
echo '<option value="'.$id.'"'.$stselected.'>'.$id.'</option>';
}

but I haven't developed one for hard coded dropdowns.
Thanks for yours.
I have been spoiled by using Coldfusion for years, but recently decided to switch to PHP for my personal site.