Forum Moderators: coopster

Message Too Old, No Replies

Php echo result from list/menu in email form

         

slimey

5:07 pm on Feb 1, 2007 (gmt 0)

10+ Year Member



Hi there this is prolly gonna be the simplest answer but im stumped.
Ive written an email form with validation in php and i want to return a value from a list menu that was selected before the form was processed to reveal some errors, just so the user doesnt have to put it back in.
I can do it with input fields easy enuf but im stumped with this.

Thas my echo code i have been using
<?php echo $_POST['name']?>

this is my list/menu
<select name="select">
<option value="" >Please Select</option>
<option value="Normal" >Goodbye Neighbours (Normal)</option>
<option value="Advanced">Goodbye Neighbours (Super Advanced)</option>
</select>

Can someone help me out?

mcibor

5:09 pm on Feb 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now look again at the code:
<select name="select">
and tell me what is the name of the field?

To help you with this try
echo $_POST['select'];

Regards
Michal

Easiest mistakes are hardest to spot

slimey

1:20 pm on Feb 2, 2007 (gmt 0)

10+ Year Member



i knew about that i just put name in as an example i just dont know where to put the php echo code into the list/menu to show the result that was selected if the page needs to be loaded again because of mistakes.

Like this is the code i use to reload what ever was put in a input feild

<input name="name" type="text" id="name" size="40" value="<?php echo $_POST['name']?>" />

SO where would i put the echo code for a list menu to reload the result selected by the user?

omoutop

1:48 pm on Feb 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The method is the same in the drop down list... just a lot easier if you create your list from a database.

Assuming you do....
<select name="somename">
<?
while ($rs = mysql_fetch_array($myresult))
{
?>
<option value="<? echo $rs['myfield'];?>" <? if ($_POST['somename']==$rs['myfield']) { echo " selected";}?>><? echo $rs['myfield'];?></option>
<?
}
?>
</select>

Assuming you do not connect to a database...
<select name="somename">
<option value="" <? if ($_POST['somename']=="") { echo " selected";}?>>Please Select</option>
<option value="Normal" <? if ($_POST['somename']=="Normal") { echo " selected";}?>>Goodbye Neighbours (Normal)</option>
<option value="Advanced" <? if ($_POST['somename']=="Advanced") { echo " selected";}?>>Goodbye Neighbours (Super Advanced)</option>
</select>

Hope this makes sence to you

slimey

12:18 am on Feb 3, 2007 (gmt 0)

10+ Year Member



Cheers worked like a charm.