I need to add validation for HTML_QuickForm. I tried but still cannot see any error message. This is the code I'm using.
$element = HTML_QuickForm::createElement('text','text1','Length');
$element->SetValue($app->GetLength());
$form->addRule('text1', 'Length should be a numeric value', 'numeric');
$form->addElement($element);
Once the form submitted,
if (isset($_POST['btnSubmit'])) {
if($form->validate()){
echo "form validated";
}else{
echo "validation fail";
}
}
I always get "form validated" although text1
has text values.
UPDATE:
I could display an alert message changing the code to this:
$form->addRule('text1', 'Length should be a numeric value', 'numeric', null, 'client');
But I need to display an error message instead of alert. Also want to highlight the error field. In documentation says that QuickForm will automatically mark required fields in the form.
Any help on this would appreciate.