"Paul Roberts" <[EMAIL PROTECTED]> wrote in message
000d01c18101$5dbb2220$01f8883e@laptop1">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.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to