SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checkbox enables textfield using with PHP

    Hello,

    I wonder if there a work around to my issue. I have a form with one checkbox which if checked enables a another field named (checkbox_text) which by default is disabled. Once the user checks the checkbox and then keyes in the value for the checkbox_text and submits the form, PHP validates the form by posting the form to itself. And if the validation fails, form is returned. The issue is that the checkbox no longer is checked and the entered value for checkbox_text is greyed out. So now if I submit the form again, checkbox and checkbox_text fails the validation.

    Any help would highly be appreciated.

    Thanks.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP validates the form by posting the form to itself
    Why? That doesn't make sense.

    Why can't you use the PHP to detect if the checkbox is checked or not and set the checked property and remove the disabled property as needed?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hello Kravvitz

    Php is able to detect but it is the javascript that is making the checbox_text greyed out if the validation fails and the page is reloaded. I gotta fiture out a way to have javascript not make any field greyed out when the page is reloaded again.

    Thanks.

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use a hidden input that the JavaScript code can check to see if it should run or not.

    So you're doing all of the validation server-side?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server side validation

    Yes, entire validation process is server-side. I am trying to stay away from javascript on this project.

    Thanks.


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
  •