Re: Elegance is the goal... Sticky form submit help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey Ash,


On Sep 11, 2010, at 10:58 AM, ash@xxxxxxxxxxxxxxxxxxxx wrote:

For a month selector, using a loop to output the months is good, as you can then within the loop check for that value sent and set the selected html attribute for that select element.

that's what I was thinking too... Now just to work out the logic :)

I should warn you that your code will throw a warning when no data has been posted to it. Consider using isset() instead to check for posted values rather than comparing a value (which might not exist) with true.

I have other code that will catch it if it's empty but a good suggestion none the less! If I stick with that code for some reason I'll be updating it to use isset()

Thanks Ash!

Thanks,
Ash
http://www.ashleysheridan.co.uk

----- Reply message -----
From: "Jason Pruim" <lists@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, Sep 11, 2010 14:49
Subject:  Elegance is the goal... Sticky form submit help
To: "PHP-General list" <php-general@xxxxxxxxxxxxx>

Hey everyone!

Hope you are having a great weekend, and I'm hoping someone might be
coherent enough to help me find a more elegant solution to a problem
that I have...

I have a form for submitting an event to a website, and if the form is
not submitted successfully (such as they didn't fill out a required
field) I want it to redisplay the form with inline errors as to what
happened and display the values they selected...

I have a working solution but was hoping for something a little more
elegant. And something that would work better for a month selector as
well... Here is the relevant code that I have that works:

<?PHP
        if ($_POST['hidSubmit'] ==TRUE & $_POST['type'] == "meeting"):
echo <<<HTML
        <select name="type" id="type">
            <option value="0">-- select type --</option>
            <option value="meeting" selected>Meeting</option>
            <option value="event" >Event</option>
        </select>
HTML;

elseif ($_POST['hidSubmit'] == TRUE & $_POST['type'] == "event"):
//if ($_POST['hidSubmit'] == TRUE & $_POST['type'] == "event") {

echo <<<HTML
        <select name="type" id="type">
            <option value="0">-- select type --</option>
            <option value="meeting">Meeting</option>
            <option value="event" selected>Event</option>
        </select>
HTML;

else:
//if ($_POST['hidSubmit'] != TRUE):


echo <<<HTML
        <select name="type" id="type">
            <option value="0" selected>-- select type --</option>
            <option value="meeting">Meeting</option>
            <option value="event">Event</option>
        </select>
HTML;
endif;

?>

which works BUT I don't want to have to have that for a month selector
or a day selector :)

Any ideas what I'm missing?



--
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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux