PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_QuickForm » Bug #4580

Minlength Validation Rule allows blank value

Details

Submitted2005-06-13 12:38 UTC
Fromjestick at kitsec dot com
StatusBogus
PackageHTML_QuickForm
PHP Version4.3.11
OSWindows 2000 Adv
Roadmaps(Not assigned)

Comments

[2005-06-13 12:38 UTC] jestick at kitsec dot com

Description:
------------
This example was taken from page 37 of the rapid prototyping-kr.pdf presentation on DB_DataObject. It should show how the minlength condition can be used with addRule method of HTML_Quickform on DB_Formbuilder Generated forms to force the user to enter a review of at least 10 characters . It works if you enter 1-9 characters, but will allow an empty review (0 characters?).

Reproduce code:
---------------
<?php
/**
* Table Definition for review
*/
require_once 'DB/DataObject.php';

class dataobjects_Review extends DB_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */

var $__table = 'review'; // table name
var $review_id; // int(8) not_null primary_key
var $book_id; // int(8) not_null
var $customer_id; // int(8) not_null
var $title; // string(64)
var $review; // string(20)

/* ZE2 compatibility trick*/
function __clone() { return $this;}

/* Static get */
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('dataobjects_Review',$k,$v); }

/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
var $fb_fieldLabels = array(
'customer_id' => 'Customer',
'book_id' => 'Book');
//var $fb_textFields = array('review');
var $fb_linkNewValue = true;
/*
function preGenerateForm(&$fb) {
$el = HTML_QuickForm::createElement('hidden','customer_id');
$this->fb_preDefElements['customer_id'] = $el;
} */
function postGenerateForm(&$form) {
$form->addRule('title', 'Please enter a title','required');
$form->addRule('review', 'Please at least try...','minlength', 10);
$form->applyFilter('__ALL__', 'trim');
}

}

Expected result:
----------------
When the form is generated from the above source, it should force the user to enter a title, and 10 or more characters in the review field. .

Actual result:
--------------
The user however can enter nothing in the review and submit the form