The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 783 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/printthread.php 16 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.31 (Linux)
File Line Function
/global.php 909 errorHandler->error
/printthread.php 16 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.31 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/printthread.php 16 require_once
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error
Warning [2] Undefined array key "showimages" - Line: 160 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 160 errorHandler->error
Warning [2] Undefined array key "showvideos" - Line: 165 - File: printthread.php PHP 8.1.31 (Linux)
File Line Function
/printthread.php 165 errorHandler->error



Form Tools
Check Init field value on validation - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Modules / Other (https://forums.formtools.org/forumdisplay.php?fid=8)
+--- Forum: Form Validation: JS + PHP (https://forums.formtools.org/forumdisplay.php?fid=18)
+--- Thread: Check Init field value on validation (/showthread.php?tid=813)



Check Init field value on validation - Shylock - Aug 20th, 2010

Hi Ben/All

I am sure I am missing something really obvious but here is my problem.

I like to have a set of initial values in my form so that people filling in the form can't go wrong. This is especially important on long lists on several columns of the same thing. However the JS validator see the example data as correct data.

E.g.
I have a three column form for prescriptions the headings are:

Item name, Item strength, Item quantity

Only the first row are required fields but there are 11 more rows for large orders.

If I put example data in the first row then the JS validator sees the fields as completed and allows submission. Is there a simple way to check if the field matches the example data and if so throw a validation error.

I could write my own validation script but I'd like to use the bundled JS validator.

Thanks
Tim


RE: Check Init field value on validation - Ben - Aug 21st, 2010

Hi Tim,

Ah, tricky one! First thing I'd suggest is checking out some plugins that would help you with this, like the jQuery coolinput plugin. Plugins like that often let you configure it to not send the values on form submission. They may well have something for checking validation as well - I'd be very surprised if they don't have something in place.

But if you're doing it manually (e.g. just providing value="default value" attributes), you'd need to hack it a bit.

Here's an example. Say you have a couple of text fields for first and last name, with the default values "Enter first name" and "Enter last name". You'd need to change your validation rules from this:

Code:
rules.push("required,first_name,Enter your first name.");
rules.push("required,last_name,Enter your last name.");

to this:

Code:
rules.push("if:first_name=Enter first name,required,blank_field,Enter your first name.");
rules.push("if:last_name=Enter last name,required,blank_field,Enter your last name.");

Then, add a hidden field to your form:
Code:
<input type="hidden" name="blank_field" value="" />

It's inelegant, but it would work. What the new rules do is check to see if the first_name and last_name fields had the default value, then continued on to check if the blank_field was empty (which it always will be). Therefore, it will always generate the error whenever the fields have the default value.

Kludgy? You betcha. So I'd definitely look into a separate plugin/script to provide the default values of your form - and one that was compatible with running validation tests on the affected fields.

Good luck!

- Ben


RE: Check Init field value on validation - Shylock - Sep 2nd, 2010

Hi Ben

Great suggestion, early tests show a combination of the coolinput plugin and the php server-side validation do a great job.

Thank you very much for your help
Tim