Re: Set checkbox always unchecked

From: Date: Wed, 03 May 2006 16:36:03 +0000
Subject: Re: Set checkbox always unchecked
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23919@lists.php.net to get a copy of this message
On 5/3/06, Stelio Gouveia <stelio@skyrove.com> wrote:
Quickforms question: i don't want quickforms to "remember" a certain form element when rules arent met Basically heres the scenario: Ive got a form that takes a number of required fields. When a user submits the form and some rules aren't met, then the user will get the same form again but this time the form remembers what form elements where changed. Now all this is fine, actually its perfect. The catch is this, my submit button is disabled on every form until the user checks my "agree checkbox". So let me iterate, user clicks checkbox and submit button is enabled, then the user clicks the submit button. But now some of the rules haven't been met. So the checkbox is still checked and the submit button is disabled. So the user have to uncheck and re-check the checkbox to enable the submit button. Whats my question again... How do i get quickforms to NOT "remember" if the checkbox was checked after validation rules not met (form elements changed)... anyone trying to achieve this, heres some basic code: Javascript: ---------- function enablebutton() {
    if(document.frmSignUp.agree.checked) {
        document.frmSignUp.submit.disabled=false;
    }
    else {
        document.frmSignUp.submit.disabled=true;
    }
} PHP: ----- $form = new HTML_QuickForm('frmSignUp', null, 'signup.php'); $form->addElement('checkbox', 'agree', null, 'I agree'); $form->createElement('submit', 'submit', 'submit', 'disabled'); $form->display();
You can't make it "not remember", it's a general feature that it remembers the field values. However, you can use setConstants() to get around this. If the form does not validate use setConstants() to force your checbox to be not checked. ... if ($form->validate()) { //process } else { $form->setConstants(array('agree' => false)); } -- Justin Patrin

« previous php.pear.general (#23919) next »