Testing my form and pulling out my hair.
Every time I make a mistake (on purpose) to check that the form works correctly I have to re-type every "input" box.
This is extremely annoying. I hadn't noticed this prior to today, as my forms are usualy extremely easy to use - standard contact forms mainly.
This current form is extremely complicated and has numerous fields that need manual input.
What was strange is all of the select and textareas keep their content when the form is submitted even when it has errors.
As I added HTML5 input types today (
as posted here) I started to look a little closer.
I am not a php'er so if you use the code as is let someone take a quick glance to ensure it's OK. I've now been using the form since posting this info and as of yet had no problems whatsoever (almost 4 days).
Note - the following changes are based on my HTML5 additions.
Change this:
case 'text':
if($name=='vericode') return "<input$t value=\"\" />";
//else pass on to next
// Added HTML5 types 29.01.2015
case 'email':
case 'url':
case 'date':
case 'number':
case 'search':
case 'color':
case 'range':
case 'time':
case 'month':
case 'week':
case 'datetime':
case 'datetime-local':
case 'tel':
return "<input$t value=\"\" />";
//else pass on to next
// End - Added HTML5 types
Into this:
case 'text':
if($name=='vericode') return "<input$t value=\"\" />";
//else pass on to next
// Added HTML5 types 29.01.2015
case 'email':
case 'url':
case 'date':
case 'number':
case 'search':
case 'color':
case 'range':
case 'time':
case 'month':
case 'week':
case 'datetime':
case 'datetime-local':
case 'tel':
return "<input$t value=\"[+$name+]\" />";
//else pass on to next
// End - Added HTML5 types
The change is the bottom return - the value has changed from
this:
return "<input$t value=\"\" />";
to this:
return "<input$t value=\"[+$name+]\" />";
What this does is: when you submit your form, all of the values are kept intact, even if they are wrong.
So what we now have to do is when the errors are shown after submitting the form, we need to use the default "required" and "invalid" classes to emphasise the element that is invalid or required.
If you take a look at the snippet code you will find this:
'requiredClass' => isset($requiredClass)?$requiredClass:"required",
'invalidClass' => isset($invalidClass)?$invalidClass:"invalid",
You can obviously override it by adding your own class names in your snippet call, for example:
[!eForm? &requiredClass=`needed` &invalidClass=`wrong`!]
[ed. note: iusemodx last edited this post 9 years, 3 months ago.]