Not passing form Select/options
Moderator: General Moderators
- Lonestarjack
- Forum Commoner
- Posts: 31
- Joined: Tue Nov 11, 2008 7:13 am
- Location: Texas
Not passing form Select/options
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.
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
First of all, post your code with a HTML form
- Lonestarjack
- Forum Commoner
- Posts: 31
- Joined: Tue Nov 11, 2008 7:13 am
- Location: Texas
Re: Not passing form Select/options
I would like to post all the code but it is a great deal of space.Ziq wrote:First of all, post your code with a HTML form
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
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
Maybe you can show a link on your script?
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);
?>- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Not passing form Select/options
Can you just post you form or just event the select element?
- Lonestarjack
- Forum Commoner
- Posts: 31
- Joined: Tue Nov 11, 2008 7:13 am
- Location: Texas
Re: Not passing form Select/options
OK I have reduced the code to a minimum:aceconcepts wrote:Can you just post you form or just event the select element?
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
You are missing an equality operator after the 'name' property:
Should be:
Also you might write it more compact like this:
This way you can add options without repeating the logic.
Code: Select all
<select class="input" name "type" size = "1">
Code: Select all
<select class="input" name="type" size = "1">
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>';
- Lonestarjack
- Forum Commoner
- Posts: 31
- Joined: Tue Nov 11, 2008 7:13 am
- Location: Texas
Re: Not passing form Select/options
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.
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.