EllisLab text mark
Advanced Search
     
Email Contact Form usage
Posted: 29 December 2011 12:41 PM
Joined: 2011-05-02
69 posts

I am testing out the Email Contact Form for a new website and have some questions.  I need to add several fields in addition to the standard set of To/From/Subject/Message.  I defined two <input type name=“required[]”> fields and that worked fine—the data is included at the top of the body of the message.  (BTW, I had no luck using “message[]”) 

Here is the primary problem:  The data is potentially indistinguishable from the receiver’s perspective.  Is there a way to add a label or some text along with what the sender enters - e.g., “Zipcode:”.  (Yes, the data probably will look very different between the additional fields, but that may not always be the case.)

Also, the EE email processor automatically does some error checking for the “standard” fields, e.g., the message field is required and a proper email address must be entered.  Is there a way of specifying that other fields are “required”.  (The “required” value for the “name” would imply that, but it doesn’t seem to work that way.)

Thanks.

And yes, I am aware of Freeform, but I would like to stay with basic EE if possible.

 
Posted: 29 December 2011 01:32 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-24
2584 posts

You can add a hidden input as a label…

<input type="hidden" name="message[]" value="---my label---" />
<
input type="text" name="message[]" value="" /> 

When the email is received the text field will have a label above, eg

—-my label—-
Some data

 Signature 

Rob - http://www.blue-dreamer.co.uk/ - because I like blue!

 
Posted: 29 December 2011 01:45 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-05-02
69 posts

Sweet.  And even sweeter for being so simple.  Thanks.

Now, any solution regarding specifying an added field as “required” and then having the EE email contact form processor forcing a return to the template if the data for a field is omitted?

 
Posted: 30 December 2011 03:45 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2004-03-22
12308 posts

Hi nroptions,

A user is already forced to click back if their data fails validation on the required fields on your form.
You could use some jQuery validation so the user does not leave the page.

 Signature 

John Henry’s Website | Follow me on Twitter

 
Posted: 30 December 2011 12:55 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2011-05-02
69 posts

Perhaps I am coding this improperly, but I am not getting the results you describe. I am assuming that if I set name=“required” for zipcode, the field cannot be left blank.  If I need to do further error checking, I will definitely take your advice about jquery.  Interestingly, even though I have done nothing to define the message field as required, leaving it blank is treated as an “error”.  Here is the block of code I am using for testing:

    {exp:email:contact_form user_recipients=“false” recipients=”*******” charset=“utf-8” redirect=“4”}

 
  <label for=“from”>Your e-mail address:</label>

  <input type=“text” id=“from” name=“from” size=“60” maxlength=“35” />
 
 
  Name:

  <input type=“text” id=“name” name=“name” size=“60” />
 
  <input type=“hidden” id=“subject” name=“subject” size=“60” value=“Join Our Mailing List” />
 
 
  Zipcode:

  <input type=“text” name=“required” size=“12” /><br >
 
 
  <label for=“message”>Message:</label>

  <textarea id=“message” class=“textarea” name=“message” rows=“18” cols=“60”></textarea>
 
  <input name=“submit” class=“submitButton” type=‘submit’ value=‘Send’ /></p>

  {/exp:email:contact_form}

 
Posted: 30 December 2011 01:02 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-24
2584 posts

Try changing required and message values to

<input type=“text” name=“required[]” size=“12” />
<
textarea id=“message” class=“textarea” name=“message[]” rows=“18” cols=“60”></textarea
 Signature 

Rob - http://www.blue-dreamer.co.uk/ - because I like blue!

 
Posted: 30 December 2011 01:24 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2011-05-02
69 posts

That does work.  Unfortunately the error message generated is “Email Message is Required”—no distinction between the Zipcode and Message field.  I took a stab at setting id=“zipcode as in

      <input type=“text” id=“zipcode” name=“required[]” size=“12” >

but it had no effect.

 
Posted: 30 December 2011 01:38 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-24
2584 posts

Can you try this version?

{exp:email:contact_form user_recipients=“false” recipients=*******” charset=“utf-8” redirect=“4”}

<input type=“hidden” id=“subject” name=“subject” size=“60” value=“Join Our Mailing List” />

<
label for=“from”>Your e-mail address:</label>
<
input type=“text” id=“from” name=“from” size=“60” maxlength=“35” />

<
label for=“name”>Name:</label>
<
input type=“text” id=“name” name=“message[]” size=“60” />

<
Label for="zip">Zipcode:</label>
<
input type=“text” id="zip" name=“message[]” size=“12” />
 
<
label for=“message”>Message:</label>
<
textarea id=“message” class=“textarea” name=“message[]” rows=“18” cols=“60”></textarea>
 
<
input type=‘submit’ value=‘Send’ />

{/exp:email:contact_form} 
 Signature 

Rob - http://www.blue-dreamer.co.uk/ - because I like blue!

 
Posted: 30 December 2011 02:07 PM   [ # 8 ]   [ Rating: 0 ]
Joined: 2011-05-02
69 posts

How could I not try after all your help.  Unfortunately there is no difference in the error message.

 
Posted: 02 January 2012 05:12 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2004-03-22
12308 posts

Hi nroptions,

I have been investigating and trying to replicate. It does indeed look buggy specifically the logic of the name attribute used for both required and message. Let me ask the devs on this one and get back to you

 Signature 

John Henry’s Website | Follow me on Twitter

 
Posted: 03 January 2012 02:34 PM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2002-05-20
12637 posts

Ah… yes, there’s a bit of (understandable) confusion on this one.  The required field doesn’t actually require the field be filled out.  What it does is put the required fields at the top of the email as sort of header-like information.

The only thing that should be triggering that message is a blank message field- that field is required regardless (though you could always make it hidden and stick in a dot or something).

For what you want- truly required fields- you’d want to use some JS validation and/or check out a more comprehensive tool (the contact form is really meant for fairly simple contact forms).  FreeForm is both free and will do exactly what you want- require the required fields be filled out.

That help?  I do realize having a field called ‘required’ is misleading- sorry for the resulting confusion!

 Signature 
 
Posted: 03 January 2012 04:04 PM   [ # 11 ]   [ Rating: 0 ]
Joined: 2011-05-02
69 posts

Thanks for persevering with the research.  As you suggest, I will look elsewhere for handling validation.

BTW, my tests show that if you add an <input> field to the form other than the standard set of email fields, it is assumed to be part of the message field.  So, leaving the additional field blank will generate an error and report “Email message is required”.

Thanks again for your help.

 
Posted: 03 January 2012 08:33 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-13
3807 posts

nroptions,

Glad to see that Robin and John were able to help you out. I’m going to close this thread now, but do feel free to post again when you need more assistance.

Sean

 Signature 

web: Caffeine Creations twitter @CS_sean