Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Lightbulb Question about a sticky month selector and forms

    Hello all,

    I have created this month selector which selects the current month. (I also have date and year ones like this too)

    PHP Code:
    function months() {
        echo 
    '<select name="month">';
            
    $months = array(
                
    'January''February''March''April''May''June''July''August''September''October''November''December'
            
    );
            foreach (
    $months as $m) {
                echo 
    '<option value="'.$m.'"';
                if (
    $m == date('F')) {
                    echo 
    ' selected="selected"';
                }
                echo 
    '>'.$m.'</option>';
            }
        echo 
    '</select>';

    However, this selector is part of a multi-page form. And I can't seem to wrap my brain around figuring out how to make it 'sticky'. For example, if it's currently August, and the user selects "December", then clicks forward in the form and then backward (Back to the month selection page), it will read August again.

    Here's the one for day too. This one would mystify me even more, as it works with a range of numbers.

    PHP Code:
    function days() {
        echo 
    '<select name="day">';
            
    $day range(1,31);
            foreach (
    $day as $d) {
                echo 
    '<option value="'.$d.'';
                if (
    $d == date('j')) {
                    echo 
    ' selected="selected"';
                    }             
                echo 
    '">'.$d.'</option>';
            }
        echo 
    '</select>';

    Also, finally, I have a number of fields that are like this:
    Code:
    <input name="guestlist[]" type="text" size="20">
    How can I make these sticky? I can't echo a whole array...

    Any hints or nudges in the right direction would be much appreciated!
    Thank you
    Sara
    Last edited by sakka; 08-15-2008 at 12:47 AM.

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Put the values into a session.

    When ever a user changes the date it will re-write the session value, which would originally be set with the current date when the page loads.



    ---
    Leonard Whistler

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Smile

    Thank you !!! That worked like a charm for the month/day dropdown.
    Now I'm stuck on this one...
    PHP Code:
    <select name="fromhour">
                                            <option value="10"<? if ($_SESSION['fromhour'] == '10') { echo ' selected="selected"'; }?>>10</option>

    ...

    </select>
    These, for some reason, aren't retaining their value. And I've declared the variable in the email script

    PHP Code:
    if (isset($_POST['fromhour'])) {
        
    $_SESSION['fromhour'] = $_POST['fromhour'];
        } 
    Any thoughts? Thank you so much for your help.

  • #4
    New Coder
    Join Date
    Nov 2007
    Posts
    41
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Just in case someone prowls around here again, I solved the sticky fields where the entries were being put into an array. Instead of just defining that the entries were going into an array (like $guestlist[]) I put $guestlist['0'] to clarify. Then I echoed that value in PHP in the field.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •