Question about how to best set up validation and error messages in formit.
In my current call and form if i don’t enter a correct email message on the page I just get a little drop over message telling me to enter a correct email address. All good.
&validate=`email:email:required`
If I then try and do the same thing for my firstname and last name fields the page reloads and i get an ugly unformatted error message at the top of the page.
Like I mentioned in my last post, you need to put ``` on a line by itself, and your code goes on the next line. I’ve updated your post, you can edit it to see how I did it.
You can do the same for your other fields. And if you don’t want the global message placeholder generated on top, just remove it => [[!+fi.validation_error_message:notempty=`<p>[[!+fi.validation_error_message]]</p>`]]
[[!FormIt?
&hooks=`email,spam,csrfhelper_formit,FormItAutoResponder,redirect`
&emailTpl=`subNotiTpl`
&emailSubject=`[[++site_name]] You have a New Subscriber Body`
&emailTo=`stories@myaddress`
&redirectTo=`25`
&validate=`email:email:required,firstname:required:minLength=^2^`
&csrfKey=`simple-form`
&fiarTpl=`sentEmailTpl`
&fiarSubject=`Thanks for Subscribing`
&fiarToField=`email`
&fiarFromName=`Ampli`
&submitVar=`form2-submit`
]]
At first glance, your setup looks good. One note of caution: hooks are executed in the order they appear in the property. If one fails, the following ones won’t be fired. This is usually the prime cause of page reloads when the form is submitted.
Also, you’re using a spam hook, but you’re not validating fields against it. So either remove the spam hook or add the missing validation rule and the corresponding field.
// in your form
<input type="hidden" name="nospam" value="">
// in your FormIt call
&validate=`nospam:blank,...`
Don’t forget to set the fiarReplyTo property in your Formit call. This is required by FormItAutoResponder.
Finally, the best way to debug FormIt is by starting with one hook and gradually adding new ones as things begin to work as expected. This will allow you to see which hooks are causing problems. I would advise starting with the email hook, then redirect, then spam and then all else. Keep note of the order mentioned above.
One last thing… Check your logs in the manager for possible errors. I’d have my eyes on FormItAutoResponder while debugging.
Next I took out all the spam protection but still getting the same result.
Call now looks like this
[[!FormIt?
&hooks=`email,FormItAutoResponder,redirect`
&emailTpl=`subNotiTpl`
&emailSubject=`[[++site_name]] You have a New Subscriber Body`
&emailTo=`stories@myaddress`
&redirectTo=`25`
&validate=`email:email:required,firstname:required:minLength=^2^`
&csrfKey=`simple-form`
&fiarTpl=`sentEmailTpl`
&fiarSubject=`Thanks for Subscribing`
&fiarToField=`email`
fiarReplyTo=`stories@myaddress`
&fiarFromName=`Ampli`
&submitVar=`form2-submit`
]]