QF: checkbox has errors but won't display them

From: Date: Fri, 07 Jan 2005 14:12:47 +0000
Subject: QF: checkbox has errors but won't display them
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16780@lists.php.net to get a copy of this message
Hi, I've worked out this problem, but thought I better share this so it goes into the archives... If your form *only* has a checkbox AND your submit button has *not* got a name, you will run into problems trying to enforce the checkbox being checked - for instance on a "I agree with the terms ...." page. Consider this: <?php require_once 'HTML/QuickForm.php'; $form = new HTML_QuickForm; $form->addElement('checkbox', 'terms',null,'I agree'); $form->addElement('submit', null, 'Go'); $form->addRule('terms', 'Please agree to the terms and conditions', 'required'); if ($form->validate()) { echo 'Succes'; } $form->display(); ?> Quickform will think the form was never submitted and thus not output any error message. Solution: add a name to your submit button or add a hidden field so at least a dummy value is sent.. Jeoren

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