Re: eval on a form
| From: | Hugh Bothwell | Date: | Mon, 10 Dec 2001 17:16:08 +0000 |
| Subject: | Re: eval on a form | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-77209@lists.php.net to get a copy of this message | ||
"Paul Roberts" <roberts_paul@bigfoot.com> wrote in message
news:000d01c18101$5dbb2220$01f8883e@laptop1...
> Hi
>
> I'm trying to pre-fill a form ( the data is passed via sessions or from
> another script).
>
> i have some check boxes on the form that i would like checked if the
> variable is present.
>
> any ideas
I would write a checkbox-presenting function - pass it the name of
the variable the checkbox represents, it will see if the variable is set
(and if so, denote it CHECKED) and name the checkbox properly.
This should encapsulate stuff nicely and make your source easier to
follow; something like
function CondCheckbox($variablename) {
$str = "<INPUT TYPE='CHECKBOX' NAME='$variablename'";
if (isset($GLOBALS[$variablename]))
$str .= " CHECKED";
return $str.">";
}
(note: I have not actually run-tested this; it should be pretty close,
though)
Then your form will look something like
Ingredients:
<FORM>
<?php
echo CondCheckbox("flour")."Flour<br>";
echo CondCheckbox("butter")."Butter<br>";
echo CondCheckbox("salt")."Salt<br>";
echo CondCheckbox("oatmeal")."Oatmeal<br>";
?>
<input type='submit'>
</FORM>
Is this something like what you were after? It would help
if you gave us a slightly more detailed idea of what sort of
data was involved.