Jump to content

PEAR HTML_Quickform validate() problem


AdB

Recommended Posts

Hi,

 

I'm just trying my hand at using Pear and Quickform package tools. Unfortunatly it seems I've a major problem with the validation.

 

If for example I try this simple example from a tutorial :

"<?php

require_once "HTML/QuickForm.php";

 

$form = new HTML_QuickForm('frmTest', 'get');

$form->addElement('header', 'hdrQuickformtest',

'QuickForm Example 2');

$form->addElement('text', 'txtName',

'What is your name?');

$form->addElement('reset', 'btnClear',

'Clear');

$form->addElement('submit', 'btnSubmit',

'Submit');

 

if ($form->validate()) {

# If the form validates then freeze the data

$form->freeze();

}

$form->display();

?>

"

 

The form validate even if I don't submit any data. How comes ?

I'm working on WinXP or 2000, with Wamp, PHP5 and Quickform 3[1].2.4pl1.

Could that be a configuration problem ? What else could be wrong ??

Other "POST" forms, more complex ones too, also fail.

 

Thanks

 

Link to comment
Share on other sites

well... trying again to see if someone has some idea today ^^;

 

Actually it seems I have a lot of troubles with validation. Aside from the fact that it validates an empty form, I also observed this :

the validate() function is not done (neither for filter nor for clients rules) when I give a file name as target to the form. I can only do it if I call a function after the form.

 

So... How can I validate my form with all the rules and filters I asked before sending data and going to another page ??

 

Thanks

 

Hi,

 

I'm just trying my hand at using Pear and Quickform package tools. Unfortunatly it seems I've a major problem with the validation.

 

If for example I try this simple example from a tutorial :

"<?php

  require_once "HTML/QuickForm.php";

 

  $form = new HTML_QuickForm('frmTest', 'get');

  $form->addElement('header', 'hdrQuickformtest',

                    'QuickForm Example 2');

  $form->addElement('text',  'txtName',

                    'What is your name?');

  $form->addElement('reset',  'btnClear',

                    'Clear');

  $form->addElement('submit', 'btnSubmit',

                    'Submit');

 

  if ($form->validate()) {

      # If the form validates then freeze the data

      $form->freeze();

  }

  $form->display();

?>

"

 

The form validate even if I don't submit any data. How comes ?

I'm working on WinXP or 2000, with Wamp, PHP5 and Quickform 3[1].2.4pl1.

Could that be a configuration problem ? What else could be wrong ??

Other "POST" forms, more complex ones too,  also fail.

 

Thanks

205503[/snapback]

 

Link to comment
Share on other sites

  • 1 year later...

You are telling the form to validate but you have not set any rules.

Here is an example using your code

 

"<?php

require_once "HTML/QuickForm.php";

 

$form = new HTML_QuickForm('frmTest', 'get');

$form->addElement('header', 'hdrQuickformtest',

'QuickForm Example 2');

$form->addElement('text', 'txtName',

'What is your name?');

//Validation Rules

$form->addRule('text', 'This box is required', required); //this would be server side vaildation

$form->addRule('text', "There are too many characters', 'maxlength', 12, 'client); //This example html_quickform would create the proper javascript to validate client side

 

$form->addElement('reset', 'btnClear',

'Clear');

$form->addElement('submit', 'btnSubmit',

'Submit');

 

if ($form->validate()) {

# If the form validates then freeze the data

$form->freeze();

}

$form->display();

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.