PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_QuickForm2 » Bug #4534

QuickForm + "soft" rules.

Details

Request #4534QuickForm + "soft" rules.
Submitted2005-06-06 07:43 UTC
Fromej dot grace at imperial dot ac dot uk
Assignedavb
StatusClosed
PackageHTML_QuickForm2
PHP Version4.3.10
OSLinux
Roadmaps0.2.0

Comments

[2005-06-06 07:43 UTC] ej dot grace at imperial dot ac dot uk

Description:
------------
This is an edited version of a discussion on pear-general:

I have come across the need to generate "soft" rules. I define a soft rule as one that can be overriden by the user, as oposed to the current "hard" rules which cannot be overridden.

What I mean by this is a typical scenario where you may have a rule that checks that a person has entered their name according to some case formatting so for example.

Surname

Rather than

sURnaMe

There are however situations where the case formatting of a surname could not fit into the typical box of "capital first letter, the rest lowercase" hence not being able to use a filter rule. For example the surnames

van Blogger
al Tranger
McTaggert

Clearly break this "convention". Of course one could add exceptions for "van", "al" "Mc" prefixes but you still can't guarentee catching them all with a "strong" validation rule.

What would be useful is to have a soft validation rule whereby, if it fails the usual message appears along with a checkbox saying "Yes I really want to submit this" that would override the associated rule.

This can be done with some hacking about using groups, rules etc but it would be nice to have a addSoftRule() method, or some such that would generate the appropriate elements if the validation failed, and deal with overriding the rule if the checkbox is set.

Of course such soft rules could be combined with hard rules (for example the 'required' rule).

Have people looked at this before? I imagine it is a common want.

Reproduce code:
---------------
Implementation:

There is no need to change the form of the rule callbacks, so for example to allow overriding of the 'required' rule one would do:

$form->addRuleSoft('name','required','Please make sure this field is filled in','Check this box to override this rule');

If the validation method fails, the usual message 'Please make sure this field is filled in' will pop up along with a checkbox with the label 'Check this box to override this rule'.

When the form is validated the associated auto-generated checkbox is tested if the rule fails, if the checkbox exists the rule is then passed.

Actual result:
--------------
In my opinion this type of concept will be very useful since it will allow tight rules to be met for a large percentage of the user input, while still allowing the user to add data that they know to be in the correct form.

[2005-06-08 17:45 UTC] ej dot grace at imperial dot ac dot uk

That's interesting. I assume that the custom rule needs the element to be in a group. Presumably somewhere in the custom rule there would be something to add checkbox element to the group, and something else to say if the check box is checked to return true.

Is that right? Would you mind sketching an outline of how this should be done, it would save a lot of time hacking around.

Perhaps I can then extend the HTML_QuickForm adding a method which wraps this process automatically?

Thanks,

-ed

[2005-06-08 17:49 UTC] ej dot grace at imperial dot ac dot uk

[Apologies if my last alteration my autoform filler re-wrote the Summary line incorrectly for me in the previous reply.]