SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot fredep57's Avatar
    Join Date
    Aug 2009
    Location
    Pacific Northwest
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checkbox validation and save state

    OK, lets say I have a checkbox for, say, agree to terms. BUT, I have a form that has required information that has to be validated against some conditions.

    Now, my problems are
    • how to validate that the box is actually checked and display the appropriate message
    • how to preserve the checked state - if checked and other errors cause the form to refresh - so the user can fix the errors


    So, for the sake of argument, my code is something like:
    HTML Code:
    <input type="checkbox" name="waiverAgree" value="<?= htmlentities($values['waiverAgree']) ?>" />
    How can I call my function VerifyForm(&$values, &$errors) where $values['waiverAgree'] needs to be processed. Or... am I trying something really different or far out??

    Thanks
    F

  2. #2
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ,

    where you want to check status of your checkbox on clientside or on serverside. ?

    Anyways just make one hidden input (textbox) and save value or status in there.
    So latter on you can check what was the last status of the checkbox.

    Cheers

  3. #3
    SitePoint Zealot fredep57's Avatar
    Join Date
    Aug 2009
    Location
    Pacific Northwest
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tejash,

    OK..... now can you give me an example of that as I don't quite understand what exactly you are aluding to.

    Thanks
    F

  4. #4
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi fredep57,

    As i understand you want to take some action on status of checkbox. I mean its selected or not selected . And if selected than what value was there. right?

    If so than what you can do is, create one hidden textbox.
    When someone checked checkbox than grab the value of checkbox and set it as a value of hidden textbox by javascript.

    Now whenever you want to check want happened, you can retrieve value of textbox. If its empty than nothing was checked. If there is some value than on base of value you can decide what further action you want to perform.

  5. #5
    SitePoint Zealot fredep57's Avatar
    Join Date
    Aug 2009
    Location
    Pacific Northwest
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm not sure I want to use javascript - have had some real problems with them in the past.

    Is there a PHP way of doing this? I think someone has done it in PHP only but can't find anything on the web that relates to it.

    Thanks and still looking for a good example, tutorial, etc. to SHOW me what and how to do this.

    F


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
  •