Here's the way I do it:

The following is an HTML code snippet with embedded PHP code for the
intelligence.

<select name="shipper>
     <option value="DHL" <? if ($shipped_via == "DHL") echo "selected";
?>>DHL
     <option value="FedEx" <? if ($shipped_via == "FedEx") echo "selected";
?>>FedEx
     <option value="UPS" <? if ($shipped_via == "UPS") echo "selected";
?>>UPS
</select>




Mark Cain


----- Original Message -----
From: "Jack Jackson" <[EMAIL PROTECTED]>
To: "[php] PHP General List" <php-general@lists.php.net>
Sent: Monday, July 25, 2005 2:37 PM
Subject: [PHP] Prepopulating form fields afer an error


> Hi,
> I have a form and it does basic error checking after submission; when
> the user omits required fields it kicks back the form with highlighted
> errors telling them the error of their ways.
>
> I've sussed out that by populating the value of the field with
> $fieldvalue I can have that form field "populated" with the data the
> user *did* enter for that field:
>
> something like
>
> <input type="text" name="email_address" value="<?php echo $email_address?>
>
> That works great. But how can I do the same thing for drop down boxes,
> when they select an option?
>
> I tried the unwieldy,
>
> <select name='blah'>
>   <?php if (!empty(blah)) {
>          echo "<option value='";
>          echo "$blah";
>          echo "'>"
>          echo "$blah";
>          echo "</option>\n";
>      }
>     ?>
>
>
> And that, lo and behold, didn't work. Can anyone offer a suggestion?
>
> Thanks in advance
> JJ
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to