SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form; checkbox value after failed submit; dropdown value without submit

    Hi

    I'm developing an events calendar for an arts website and one of the options is to add an event. When a user adds an event they put in the start date, the end date, the start time and the end time using drop down menus. This works fine.

    However, if a user wants to add more than one date I have a problem. I used a dropdown menu to select how many more date the user wants to add. Like this:

    HTML Code:
    Add Other Dates: <select name="dates">
                            <option value="1">1</option>
                            <option value="2">2</option>
                             .....
                             <option value="6">6</option>
    So when a user selects '1' I use javascript to reload the page and pass 1 into the page via $_GET. Like this:

    Code:
    location.href = 'url?dates=1';
    This works fine to an extent. Since the drop down menu to choose how many more dates the user wants to add is not the first in the form, when the user chooses, it reloads the whole page erasing everything that was typed in the form before it.

    I use isset to prevent this from happening but that only works when the user presses submit and there's an error.

    I have seen forms on the internet that check values of the form as they are put in without reloading the page and I was hoping to do that for this field but I can't find any tutorial or help on the internet or even in the books.

    The last result would be to put fields for all additional dates in the form without letting the user choose how many they want to add which would make my big form even bigger but I was wondering if someone knew of a better way?

    Also, I have a problem with keeping checkboxes that were checked before the user submits a form, still be checked after a user hits submit but there is an error or something and the user is shown the form again. My checkboxes look like this:

    HTML Code:
    Holidays:
    <input type="checkbox" value="New Year's" name="holidays[]">New Year's
    <input type="checkbox" value="Christmas" name="holidays[]">Christmas
    ...there are about 30 of these...
    Does anyone know how to make this correction? or can point me in the right direction?

  2. #2
    SitePoint Member
    Join Date
    Jul 2009
    Location
    Devon, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not ask the user to select the number of dates THEN give them the form to complete?

    The option you're thinking of is going down the AJAX route.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you need to store the values somewhere when submit happens. Be it session, cookie or object .. just some place where from you can fetch them again after a failed submit. And after failed submit you must reconstruct the form with the values selected before submit. Or use ajax to do the checks on the fly.

  4. #4
    SitePoint Member
    Join Date
    May 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for fast replies!

    Actually, the ideal way for me would be to use Ajax to check the form fields on the fly but there are two problems with that:

    1. I'm not that good at javascript/ajax but I'm a fast learner
    2. I just spent 4 hours going through my local border's and barnes and noble Ajax books and none of them had a decent tutorial or explanation on how to do this; and I've searched on the internet also but came up with nothing.

    Dou you guys know where I can find a tutorial on how to use Ajax with forms?

  5. #5
    SitePoint Member
    Join Date
    Jul 2009
    Location
    Devon, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

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