0

I'm setting up an email contact form for a page, it's working fine for logged in users, but for non logged users, they get the message:

A valid sender email is required

I'm sure it's the {member_email} field that's causing it, it's obviously not picking up the field if your not logged in. Does anybody know a way to use this form without the {member_email} field, or a way to fill this field for someone whos not logged in?

  {exp:email:contact_form user_recipients="no" replyto="yes" recipients="[email protected]" charset="utf-8"}
    <h2>Register</h2>
    <p>
            <label for="name">Your Name:</label><br />
            <input type="text" name="required[]" size="40" />
    </p>
    <p>
            <label for="institution">Institution/Organisation</label><br />
            <input type="text" id="Institution" name="required[]" size="40" placeholder="institution/organisation" />
    </p>
    <p>
            <label for="number">Contact Number</label><br />
            <input type="text" id="number" name="required[]" size="40" placeholder="contact number" />
    </p>
    <p>
        <label for="email">Email Address</label><br />
        <input {if logged_in} value="{member_email}"{/if} {if logged_out} type="text" value=""{/if} id="from" name="from" size="40" />
    </p>

      <p>
            <input type="text" id="subject" name="subject" size="40" value="Contact Form" style="display:none;"/>
            <textarea type="hidden" id="message" name="message" rows="18" cols="40" placeholder="Register" style="display:none;">
                    Sent on:  {current_time format="%l %mF %Y"}
            </textarea>
    </p>


    <p>
            <input name="submit" type='submit' value='Register' />
    </p>

{/exp:email:contact_form}

2 Answers 2

3

You just need to ask user to entered his email.

<p>
            <input {if logged_in}type="hidden" value="{member_email}"{/if} {if logged_out} type="text" value=""{/if} id="from" name="from"  />
</p>

or you can replace FROM email for quest with your own (in all case you have email field)

<p>
<input type="hidden" id="from" name="from" {if logged_in}value="{member_email}"{/if}{if logged_out value="[email protected]"{/if} /> 
</p>
2
  • Hi Max, thanks for help, I've updated the code above with your suggestion, it's working for both logged in and logged members. Just one thing thing though, it's not including the email address in the body of the email that's sent, I think because it doesn't have the required[] field. Is there anyway around this, or am I missing something?
    – Mark
    Nov 19, 2013 at 12:34
  • You update code with my first solution? In this case email is not in the email body, but in FROM email field. Possible in your case will be more useful take second solution, replace FROM with your email (like "[email protected]") and keep email with name="required[]" input. p.s. btw did you know that you can use it next way : <input type="hidden" name="required[]" value="Email:" /> <input type="text" name="required[]" size="40" placeholder="contact email" />
    – Max Lazar
    Nov 19, 2013 at 12:41
3

You'd have to have them fill out that field themselves. Currently, you have it hidden with display:none. Also, your input related to the Email Address label has a placeholder of "contact number."

Try adding a logged_in conditional around the display:none inline style.

<p>
        <label for="email">Email Address</label><br />
        <input type="text" id="email" name="required[]" size="40" placeholder="email address" />
</p>
<p>
        <input type="text" name="from" size="40" value="{member_email}" {if logged_in} style="display:none;"{/if}/>
</p>

I'm not sure what you're trying with the required[] field and why someone would input their email address twice, but I'll trust you have that figured out since you didn't ask about it.

1
  • Hi Stephen, Thanks for your help, the required[] field is so the value that's entered will be included in the body of the email that's generated. If I leave that out, the email address is not included in the text of the email that's sent. It seems that the only way I can get the form to work as I want, without an EE error and with the email address included in the text of the email that's sent is to include the email field twice. I've updated the code above, which is working for logged in and out members, but dosn't include their email address in the text of the email that's sent:
    – Mark
    Nov 19, 2013 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.