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 any field.

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

<div class="common-form">
<h5 class="title">
Contact us
</h5>
@
if (ViewData["CaptchaFormResult"] == "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="CaptchaFormAction" value='SENDEMAIL' /><!-- SENDEMAIL or ADDCONTENT -->
<table>
<tbody>
<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="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>
Code:
</th>
<td>@Html.Raw((string)ViewData["CaptchaImage"])
@Html.Raw((string)ViewData["CaptchaReloadLink"])
@if (ViewData["CaptchaSuccess"] != null && !(bool)ViewData["CaptchaSuccess"])
{
   
<strong style="color: red;">Captcha Validation FAILED!</strong>
}
<input type="text" id="captcha" name="captcha" data-val-required="Code is required" data-val="true" />
@Html.ValidationMessageForInput(
"captcha")

</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:

add plugin on view kooboo

Custom Captcha plugin return next values:

  • ViewData["CaptchaImage"] - image with captcha code (with IMG tag and link for reload)
  • ViewData["CaptchaImageWithoutLink"] - image with captcha code (only IMG tag, but without link for reload)
  • ViewData["CaptchaReloadLink"] - link for reload captcha image (with A tag)
  • ViewData["CaptchaSuccess"] - true (if captcha is valid) or false (if captcha is not valid)
  • ViewData["CaptchaFormResult"] - 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 Jan 13, 2013 at 6:38 PM by EllaSea, version 2

Comments

No comments yet.