Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've had some experience with modifying the output of XForms within EPiServer, but I have not added any captcha controls before. I hope I can help you get there!</p> <p>I do all modification of the XForms output on the XFormControl.BeforeLoadingForm event. You can assign an event handler to this either within the Global.asax.cs or create a static initializer class that instantiates the first time somebody navigates onto a form page (my template class inherits from this initialiser class.) I only did this because I needed a nice deployable solution without changing Global.asax. Anyway, I digress.</p> <p>For now, I'd suggest doing it within the Global.asax.cs just to get you working. There is example code within the Global.asax.cs that is installed with the PublicTemplates pack. Look for the 'Global XFrom Events' region.</p> <p>The 'markup' of the XForm is exposed though the BeforeLoadingForm event arguments.</p> <pre><code>e.FormDefinition </code></pre> <p>Modifying this string will change the rendered output of the form, regardless of what the user created within the XForm editor. For example:</p> <pre><code>e.FormDefinition += "&lt;asp:HyperLink runat=\"server\" Text=\"HyperLink\" /&gt;"; </code></pre> <p>This example obviously adds markup to what currently exists, but you can completely transform the original markup if you wish. (I use regex to transform the tables into div/fieldset tags)</p> <p>I hope this helps you get to your solution.</p> <p>Example code for Global.asax.cs</p> <pre><code>protected void Application_Start(Object sender, EventArgs e) { XFormControl.ControlSetup += new EventHandler(XForm_ControlSetup); } public void XForm_ControlSetup(object sender, EventArgs e) { XFormControl control = (XFormControl)sender; control.BeforeLoadingForm += new LoadFormEventHandler(XForm_BeforeLoadingForm); } public void XForm_BeforeLoadingForm(object sender, LoadFormEventArgs e) { XFormControl formControl = (XFormControl)sender; //We set the validation group of the form to match our global validation group in the master page. formControl.ValidationGroup = "XForm"; e.FormDefinition += "&lt;asp:HyperLink runat=\"server\" NavigationUrl=\"#\" Text=\"HyperLink\" /&gt;"; } </code></pre> <p>EDIT:</p> <p>Sorry, the above code will help you integrate the captcha control into your form but completely missed out the part of actually checking whether the captcha control input is valid before submitting the form!</p> <p>I agree that you would perform a check on the control within XFormControl.BeforeSubmitPostedData. Then if the captcha is not valid output an error message and set e.CancelSubmit to true.</p> <p>RESPONSE TO COMMENTS:</p> <p>I may be simplifying things too much but this is a quick example of what I think you need. In your XForm user control code you need something similar to this:</p> <pre><code>protected override void OnInit(EventArgs e) { base.OnInit(e); this.FormControl.BeforeLoadingForm += new LoadFormEventHandler(FormControl_BeforeLoadingForm); this.FormControl.BeforeSubmitPostedData += new SaveFormDataEventHandler(FormControl_BeforeSubmitPostedData); } void FormControl_BeforeLoadingForm(object sender, LoadFormEventArgs e) { e.FormDefinition += "&lt;recaptcha:RecaptchaControl runat=\"server\" id=\"CaptchaControl\" /&gt;"; } void FormControl_BeforeSubmitPostedData(object sender, SaveFormDataEventArgs e) { /* find the captcha control e.g. FormControl.FindControl("CaptchaControl") or otherwise * test if the control is valid * if not valid e.CancelSubmit = true (show error etc.) */ } </code></pre> <p>As for the above example, as long as you have the Recaptcha control registered in your web.config or at the top of your template/usercontrol markup then it should work. You should find that the captcha control is just added onto the end of the form (probably not where you really want it to be, but this can be changed in your own way as long as you can pinpoint where you want to insert it within the e.FormDefinition string.</p> <p>Where "FormControl" is the XForm control within your user control markup.</p> <p>EDIT (23/12/2010):</p> <p>The captcha control must be registered within the web.config NOT at the top of the markup file.</p> <pre><code>&lt;add tagPrefix="recaptcha" namespace="Recaptcha" assembly="Recaptcha" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload