Module

Archived
Forum
(read-only)


For official support, visit the official support site »

Email Form

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4

Back to this add-on's main page
View Other Add-ons From Rein de Vries

     

custom errors?

General (Resolved)

bjp
bjp

Is it possible to define custom errors for input fields?  Thanks

Reinos
# 1
Developer
Reinos

You can do something like this

{if body:error != ''}this is a custom error{/if} 
{exp:email_form:form
 required_fields
="body|inputfield"
 
error_msg:body="is nodig"
}
 
<!-- You can declare as many field you wish to use inside your formjust be creative. -->
 
{if body:error != ''}this is a custom error{/if}
 
<textarea name="body">{body:value}</textarea>

 
{if inputfield:error != ''}this is yet another custom error{/if}
 
<input type="text" name="inputfield" value="{inputfield:value}" />
 <
input type="submit"/>

 
{email_template
  to
:name="John Doe"
  
to:email="test@example.nl"
  
from:name="William Doe"
  
from:email="test@no-example.com"
  
subject="Test email"
 
}
 This email is sent to {to
:name}
  
The following fieldthat are declared inside the form can be used inside this template
  
{inputfield}
  {body}
 {
/email_template}



{
/exp:email_form:form} 
bjp
# 2
bjp

Works well, thanks!

Reinos
# 3
Developer
Reinos

No problem.

* feel free to review the addon.

Best,
Rein

r_tait
# 4
r_tait

Not working for me with this simple form please help! the “has-error” never shows on submitting blank:

{exp:email_form:form required_fields="name"}
   
<div class="row">
    <
div class="col-xs-6">
     <
div class="form-group{if name:error != ''} has-error{/if}">
      <
label for="name">{exp:transcribe:replace name="name"<span class="light-green">*</span></label>

      <
input type="text" class="form-control" name="name" id="name" placeholder="{exp:transcribe:replace name='name'}"/>
     </
div>

     <
div class="form-group">
      <
button type="submit" class="btn btn-success">{exp:transcribe:replace name="submit"}</button>

      <
span class="green">{exp:transcribe:replace name="required_fields"}</span>
     </
div>
    </
div>
   </
div>

   
{email_template
   to
:name="John Doe"
   
to:email="test@test.com"
   
from:name="William Doe"
   
from:email="no-reply@test.com"
   
subject="Test email"
   
}
   {name}
   {
/email_template}
  {
/exp:email_form:form} 
Reinos
# 5
Developer
Reinos

What if you quote the if like this:

{if ‘{name:error}’ != ‘’} has-error{/if}

r_tait
# 6
r_tait

That causes the IF statement to not work at all it outputs: <div class=“form-group’ != ‘’} has-error”>