Re: QuickForm javascript / setDefaults

From: Date: Fri, 09 Apr 2004 08:26:14 +0000
Subject: Re: QuickForm javascript / setDefaults
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-11757@lists.php.net to get a copy of this message
Hi! Peter, first of all: your problem description was completely misleading. You mentioned *javascript* validation, while in reality had problems with *server-side* one. I'd answer much sooner if the problem was correctly described... Second thing: submitted values validation is designed to, uh, validate *submitted* values. If you do a HTTP redirect, you don't have *any* submitted values, thus the errors. Defaults are not considered submitted, they are just for display purposes. Third thing: consider looking at HTML_QuickForm_Controller, it was designed with such applications in mind. Peter McMillan wrote:
I'm using the FuseBox method for development. The process goes like this (psuedo-code): case1: display regform (the QuickForm) case2: query and display quiz questions case3: display grade if grade < 80, back to case1 else send mail, display congratulations Here's the code from the QuickForm: require_once('HTML/QuickForm.php'); require_once ("HTML/QuickForm/select.php"); $form = &new HTML_QuickForm('regform', 'POST', 'index.php?fuseaction=home.insertregistration'); $form->setDefaults(array(
'First'    =>    @$_SESSION['First'],
'Last'    =>    @$_SESSION['Last'],
'Unit'    =>    @$_SESSION['Unit'],
'Title'    =>    @$_SESSION['Title'],
'ServiceCenter'    => @$_SESSION['ServiceCenter'],
'Email'    =>    @$_SESSION['Email'],
'Phone'    =>    @$_SESSION['Phone']
)); $form->addElement('text', 'First', 'First:'); $form->addRule('First', 'Please enter your First name.', 'required', false, 'client'); $form->addRule('First', 'Invalid characters in First name.', 'regex', '/^[ a-zA-Z\',.-]+$/','client'); $form->addElement('text', 'Last', 'Last:'); $form->addRule('Last', 'Please enter your Last name.', 'required', false, 'client'); $form->addRule('Last', 'Invalid characters in Last name.', 'regex', '/^[ a-zA-Z\',.-]+$/','client'); $form->addElement('text', 'Unit', 'Unit:'); $form->addRule('Unit', 'Please enter your Unit.', 'required', false, 'client'); $form->addRule('Unit', 'Invalid characters in Unit.', 'regex', '/^[ a-zA-Z\',.-]+$/','client'); $form->addElement('text', 'Title', 'Title:'); $form->addRule('Title', 'Please enter your Title.', 'required', false, 'client'); $form->addRule('Title', 'Invalid characters in Title.', 'regex', '/^[ a-zA-Z\',.-]+$/','client'); $form->addElement('select','ServiceCenter','Service Center:', $servicecenters); $form->addRule('ServiceCenter', 'Service Center is required', 'required', false, 'client'); $form->addRule('ServiceCenter','Please enter your Service Center', 'regex', '/^[0-9]+$/', 'client'); $form->addElement('text', 'Email', 'Email:'); $form->addRule('Email', 'Please enter your Email address.', 'required', false, 'client'); $form->addRule('Email', 'Your Email address is incorrect', 'email', null, 'client'); $form->addElement('text', 'Phone', 'Phone:'); $form->addRule('Phone', 'Please enter your Phone.', 'required', false, 'client'); $form->addRule('Phone', 'Invalid characters in Phone.', 'regex', '/^[0-9\'-]+$/','client'); // Add a submit button called submit and "Send" as the text for the button $form->addElement('submit','submit','Send');
    $form->applyFilter('_ALL_', 'escapeValue');
    $form->applyFilter('_ALL_', 'EscapeShellCmd');
    $form->applyFilter('_ALL_', 'trim');
    // If the form is submitted, validate via javascript that the field data is valid.
//We'll revalidate again prior to insertion. if ( $form->validate() ) {
    // Form is validated, then process the data.
    $form->freeze();
        Header("Location: http://". $_SERVER["SERVER_NAME"] . $_SERVER["SCRIPT_NAME"] . "?fuseaction=home.insertregistration");
} else {
    // If not submitted, display the form
    $form->display();
} thanks, Peter On 2004-Apr -07, , at 10:18 AM, Alexey Borzov wrote:
Hi! Peter McMillan wrote:
I have a QuickForm working correctly. My app is a quiz. The user registers, takes the quiz and is passed back to the form to start again if they don't pass the quiz. I record the randomly generated set of questions and the user info to a table for each quiz attempt. I've created via setDefaults, $_SESSION vars that contain the First, Last, etc. My problem is that when the user is returned to the form the javascript errors are displayed for the required fields and the setDefaults values are filling in the form fields correctly. The result being that I've got bogus error messages being displayed; a distracting UI.
Ugh, how exactly do you return to the form and how exactly do you fill in the values? Via javascript?


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