Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hello again!

I have this simple email contact form that I'm using in my site for visitors to send questions etc. But right now in "From" and "Subject" fields it just enters previously set values which is a bit inconvenient. I would like to have senders email and subject he enters in my contact form to show up.

Here's my code for the form itself.
Code: Select all
<cms:form action='' method='post' id='contact_form'>
               <h3>Contact Us</h3>
            <ul>                  
               <li class="clearfix">
                  <label for="name">Name</label>
                  <cms:input type='text' name='name' id='name' required='1' />
                  <div class="clear"></div>
                  <cms:if k_error_name>
                  <p id='name_error' class='error' style="display:block">Insert a Name</p>
                  </cms:if>
               </li>
               <li class="clearfix">
                  <label for="email">Email Address</label>
                  <cms:input type='text' name='email' id='email' required='1' />
                  <div class="clear"></div>
                  <cms:if k_error_email>
                  <p id='email_error' class='error' style="display:block">Enter a valid email address</p>
                  </cms:if>
               </li>
               <li class="clearfix">
                  <label for="subject">Subject</label>
                  <cms:input type='text' name='subject' id='subject' required='1' />
                  <div class="clear"></div>
                  <cms:if k_error_subject>
                  <p id='subject_error' class='error' style="display:block">Enter a message subject</p>
                  </cms:if>
               </li>
               <li class="clearfix">
                  <label for="message">Message</label>
                  <cms:input type='textarea' name='message' id='message' required='1' rows="30" cols="30"></cms:input>
                  <div class="clear"></div>
                  <cms:if k_error_message>
                  <p id='message_error' class='error' style="display:block">Enter a message</p>
                  </cms:if>
               </li>
               <li class="clearfix">
                  
               <cms:if k_success>   
               <p id='mail_success' class='success' style="display:block; background: rgb(255, 255, 255); background: rgba(255, 255, 255, .7); border-radius: 3px; padding: 5px; margin-left: 20px;">
               <span>Thank you. We will get back to you as soon as possible.</span>
               </p>
               
               <cms:send_mail from=k_email_from to=k_email_to subject='Feedback from your site'>
                  The following is an email sent by a visitor to your site:
                  <cms:show k_success />
               </cms:send_mail>
               </cms:if>
               
               <p id='mail_fail' class='error' style="background: rgb(255, 255, 255); background: rgba(255, 255, 255, .7); border-radius: 10px;">
               Sorry, an error has occured. Please try again later.
               </p>
               
               <div id="button">
               <input type='submit' id='send_message' class="button" value='Submit' />
               </div>
               </li>
            </ul>
         </cms:form>

I'm also using phpmailer but that shouldn't change anything here.

Thank you!

P.S. I'm sorry if there has been a question like this before. Ran through search results and didn't see it.
Hi :)

As mentioned in the docs on forms (http://docs.couchcms.com/concepts/forms.html), all the submitted values of a form are available as variables prefixed by 'frm_'.
So, submitted values of the two fields you are interested in (named 'email' and 'subject') would be available as 'frm_email' and 'frm_subject'.

You can make use of the submitted 'subject' as either this -
Code: Select all
<cms:send_mail from=k_email_from to=k_email_to subject=frm_subject>

or this (please notice the double-quotes) -
Code: Select all
<cms:send_mail from=k_email_from to=k_email_to subject="<cms:show frm_subject />">

We can do exactly the same with the 'email' field e.g. as follows -
Code: Select all
<cms:send_mail from=frm_email to=k_email_to subject=frm_subject>

or
Code: Select all
<cms:send_mail from="<cms:show frm_email />" to=k_email_to subject=frm_subject>

However, it is not recommended that you use the submitted email in this manner.

The problem is that most hosts refuse to process email addresses that do not belong to that particular site's domain (and, for sure, the email address of your visitor will not belong to your site's domain).

The prescribed way of using the visitor's email is through the 'reply_to' parameter as follows
Code: Select all
<cms:send_mail from=k_email_from to=k_email_to reply_to=frm_email subject=frm_subject>

or
Code: Select all
<cms:send_mail from=k_email_from to=k_email_to reply_to="<cms:show frm_email />" subject=frm_subject>

This way, when you press 'Reply to' for the message in your email client, the visitor's address will be automatically selected as the target.

Hope it helps.
Thank you!
It's exactly what I was looking for. I guess I missed it when I was reading documentation.
3 posts Page 1 of 1

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest