form to external dll

Jan 21, 2011 at 8:37 AM

hello,

New question :) how do i get form values to a external dll.

The external dll part is working thanks to the example here: http://xsltdb.codeplex.com/Thread/View.aspx?ThreadId=242244

 

Coordinator
Jan 21, 2011 at 10:14 AM

Hi,

As far as you are in the web context you have access to Request object. If your page was submitted you can use it as follows:

If you mean using form values inside DLL:

  1. Add reference to System.Web in your DLL project
  2. Use System.Web.HttpContext.Current.Request["inputName"] to access form values inside DLL.

If you just want to send values as parameters you can use mdo:request('inputName'). Here is a simple example.

<msxsl:script language="C#" implements-prefix="script">
   public int someFunc(string fieldValue)
   {
        return fieldValue.Length;
   }
</msxsl:script>

<xsl:template match="/">
  <!-- Emulate stateful control -->
  <input name="inputName" type="text" value="{mdo:request('inputName')}"/>
  ({{script:someFunc(mdo:request('inputName'))}})
  <br/>
  <button>Calculate Length</button>
</xsl:template>

 

Jan 21, 2011 at 12:14 PM

If I want to have a page with the form and a page for the processing. Are there 2 modules required or is it possible in one xsltdb module?

Developer
Jan 21, 2011 at 12:31 PM

mvanlaar,

you could use an mdo:service section (which is actually a separate template) to simulate the second page, calling it from the main template (where you get the url via mdo:service-url()) with ajax calls.

For example I use this approach in XSLider and XSLideShow, two xsltdb modules I'm developing: you might look at my code, which is absolutely not perfect but maybe can be useful for you.

If you don't want to use ajax, you might use xsl:choose to divide your template in sections, for example "view" and "save", to be loaded when needed. You can find something like this also, in my templates.

 

Coordinator
Jan 21, 2011 at 12:32 PM

One module is quite enough

Coordinator
Jan 21, 2011 at 12:49 PM

... accidentally submited uncompleted...

The main question here is how are you going to send form to another page? I know a few ways

  • Changing action attribute of a form (affects browser's addres line)
  • Transferring request to another page (does not affect browser's addres line)
  • Post form using AJAX or process results using special javascript call (doesn't affect browser's window content), you can manually inject results in current HTML.

What is your one?

XsltDb supports all of those methods.

 

Jan 25, 2011 at 6:23 AM

Is there a example (because the form documentation is missing) of a page with a form and submitting it to a next page?

Coordinator
Jan 25, 2011 at 8:01 AM

I have no such sample at the moment.

I could create one for you but I must understand the nature of the requirement to process form values on page other than form's page.

If you are implementing a WIZARD - you better process form on the form's page. If everything is successfull - just redirect to next page with mdo:redirect(url) function:

<xsl:if test="mdo:param('@cmd') = 'save'">

   <!-- Here goes a code that saves fields somehow -->

   <!-- After that, just redirect user to next page-->
   <xsl:execute select="mdo:redirect('/next_page_relative_url.aspx')" />

</xsl:if>

<!-- The forn itself -->
Field One: <input name="field-1" /><br/>
Field Two: <input name="field-1" /><br/>
<a class="CommandButton" href="{mdo:submit('@cmd', 'save')}">Next &gt;&gt;</a><br/>

If it is not your case - whet is your one then?

Feb 9, 2011 at 10:52 AM

How can i merge this with captha example?

Coordinator
Feb 9, 2011 at 7:36 PM

You have 2 options here:

1. If you are using reCAPTCHA you can validate it client-side. So you can add a validator to mdo:submit () and check CAPTCHA using ajax (http://code.google.com/apis/recaptcha/docs/verify.html).

2. If you are using telerik CAPTCHA you need to create mdo:pre-render region as you have to call mdo:page-validate() that works only in.

Here is a complex sampl with jquery validation and Telerik CAPTCHA.

 

<style type="text/css">
  .error { color: red; }
</style>

<script type="text/javascript" 
  src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.pack.js" />
  
<script type="text/javascript">
  function validateForm() {
    return $("form").validate().form();
  }
</script>

<div>Name: <input name="name" class="required" value="{mdo:form('name')}" /></div>
<div>E-Mail: <input name="email" class="required email" value="{mdo:form('email')}" /></div>
<mdo:asp xmlns:telerik="telerik">
  <telerik:RadCaptcha runat="server" ID="captcha" ErrorMessage="Captcha not solved" />
</mdo:asp>

<a href="{mdo:jsubmit('validateForm', '@action', 'save')}">Save</a>

<mdo:pre-render>
  <xsl:if test="mdo:param('@action')='save'">
    <xsl:execute select="mdo:page-validate()"/>
    <xsl:if test="mdo:aspnet('#captcha.IsValid')">
      <!-- process form and redirect to next page -->
    </xsl:if>
  </xsl:if>
</mdo:pre-render>