For use this plugin with send e-mail form (for example - "feedback" or "contact us" form on your site for anonymous users), you need to create view with form with some of next field (field "Body" is required):

  • From (it is not recommended to use) - the e-mail address of the sender (If you are using the authorized STMP account, you are not allow to use a different FROM email. You need to use an anonymous smtp to send email using any FROM email address.). If you want that user tell you his contact e-mail, use field "contact_email".
  • Subject (it is not recommended to use) - short heading of the message (it will be used as letter heading). Many users can't normally formulate heading of the message, therefore it is not recommended to use this field. If field is empty, subject will be this message: "FeedBack from site <site name>".
  • Body (required field) - text of message (it will insert into body of letter with additional fields)
  • Additional fields: (it will insert into body of letter)
    • contact_email
    • contact_name
    • contact_phone
    • contact_address
    • contact_firm

This sample view for send "contact us" form: (online-demo sample)

<div class="common-form">
  
<h5 class="title">
       Contact us
</h5>
   @
if (ViewData["ReCaptchaFormResult"] == "Mail was sent")
   {
      
<p style="color: green;">
          
<strong>Thank you for feedback! Your message was save.</strong></p>
   }
  
<form method="post" action="">
   @Html.AntiForgeryToken()
  
<!-- this contact form will send an email to the email address defined in system/settings/smtp-->
   @*
<input type="hidden" name="RedirectUrl" value='@Url.FrontUrl().PageUrl("Thankyou")'/>*@
  
<input type="hidden" name="recaptcha_form_action" value='SENDEMAIL' /><!-- SENDEMAIL or ADDCONTENT -->
  
<table>
      
<tbody>
           @*
<tr>
               <th>
                   <label for="from">
                       From email:</label>
               </th>
               <td>
                   <input type="text" id="from" name="From" data-val-required="From is required" data-val="true"
                     data-val-regex-pattern = "\b[a-zA-Z0-9._%\-+']+@@[a-zA-Z0-9._\-]+\.[a-zA-Z]{2,6}\b"
                     data-val-regex = "Not valid e-mail." />
                   @Html.ValidationMessageForInput("From")
               </td>
           </tr>
           <tr>
               <th>
                   <label for="subject">
                       Subject:</label>
               </th>
               <td>
                   <input type="text" id="subject" name="Subject" />
               </td>
           </tr>
*@
          
<tr>
              
<th>
                  
<label for="body">
                       Body:
</label>
              
</th>
              
<td>
                  
<textarea id="body" name="Body" cols="20" rows="10" data-val-required="Body is required"
                      
data-val="true"></textarea>
                   @Html.ValidationMessageForInput(
"Body")
              
</td>
          
</tr>
          
<tr>
              
<th>
                  
<label for="contact_name">
                       Contact name:
</label>
              
</th>
              
<td>
                  
<input type="text" id="contact_name" name="contact_name" />
              
</td>
          
</tr>
          
<tr>
              
<th>
                  
<label for="contact_email">
                       Contact e-mail:
</label>
              
</th>
              
<td>
                  
<input type="text" id="contact_email" name="contact_email" />
              
</td>
          
</tr>
          
<tr>
              
<th>
                  
<label for="contact_phone">
                       Contact phone:
</label>
              
</th>
              
<td>
                  
<input type="text" id="contact_phone" name="contact_phone" />
              
</td>
          
</tr>
          
<tr>
              
<th>
                  
<label for="contact_address">
                       Contact address:
</label>
              
</th>
              
<td>
                  
<input type="text" id="contact_address" name="contact_address" />
              
</td>
          
</tr>
          
<tr>
              
<th>
                  
<label for="contact_firm">
                       Firm name:
</label>
              
</th>
              
<td>
                  
<input type="text" id="contact_firm" name="contact_firm" />
              
</td>
          
</tr>
          
<tr>
              
<th>
                   Code:
              
</th>
              
<td>
                  
@if (ViewData["ReCaptchaSuccess"] != null && !(bool)ViewData["ReCaptchaSuccess"])
                   {
                      
<strong><span style="color: red;">Captcha Validation FAILED!</span></strong>
                   }
                  
@Html.Raw((string)ViewData["ReCaptchaScript"])
               </td>
          
</tr>
          
<tr>
              
<th>
              
</th>
              
<td>
                  
<input type="submit" name="submit" value="submit" /><br />
              
</td>
          
</tr>
      
</tbody>
  
</table>
  
</form>
</div> 

Also you need to add this plugin on your view:

ReCaptcha plugin return next values:

  • ViewData["ReCaptchaScript"] - js-script for recaptcha input form 
  • ViewData["ReCaptchaSuccess"] - true (if captcha is valid) or false (if captcha is not valid) 
  • ViewData["ReCaptchaFormResult"] - result of execute plugin: 
    • "Mail was sent" 
    • "Mail was not sent. Error sendig mail. " + error message 
    • "Mail was not sent. Body is empty."

Last edited Mar 20, 2012 at 3:02 PM by EllaSea, version 4

Comments

No comments yet.