Jump to content

submit, whitelist value as selected


bwakad
 Share

Recommended Posts

- EDIT - if I just use plain old html and php (no function) I can simply say $input->post->my-field-variable in the $selected = ... etc.

I guess a function to output a select is not a good idea if you want to retrieve back it's value... - END EDIT -

I don't know if this is good practise but I made this function so I could simply use: select("myfield"); in my template, which make the code less. Just a reminder, the "select" word I use here is just to make it clear.

I use these on a form submit, posting to the same page, and errors get displayed for empty values etc. But I would like to retrieve back the value selected in a select to make it more user friendly. I thought it was the whitelist doing that, but noooo... I tried with input->post->what and no result either.

I use this for error checking...

$myfield = $input->post->myfield;
function select($what) {
$pages = wire("pages");
$out =        "<select name='{$what}' id='{$what}' aria-label='{$what}' required>
            <option value=''>your {$what}</option>";            
            foreach($pages->get("/personal-info/{$what}/")->children() as $what) {
$out .=        $selected = $what->name == $input->whitelist->what ? " selected='selected' " : '';
$out .=        "<option$selected value='{$what->name}'>{$what->title}</option>";
            };

$out .=        "</select>";

echo $out;
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...