Welcome to the Learning Center

The Guide | Knowledge Base | FAQ

Browse it all or refine your selection using the filters below on the left.

How To Send Data Between XMP Forms and Templates

A brief overview to demonstrate the options for passing data around in XMod Pro

By: Angus Beare On: 11/09/2010

Link to this Article
https://dnndev.com/Learn/Guide/Article/How-to-send-data-between-XMod-Pro-Forms-and-Templates

I often see posts on the DNNDEV forum asking for help passing parameters between XMod Pro objects. I decided to try and write a brief overview to demonstrate the options for passing data about in XMod Pro.

Firstly, let’s assume you are experimenting with Templates. You now know how to build a basic template or you have realised you can have several templates in one XMod Pro module. Let’s also assume you want to send data from one template to another in separate modules. Enter the <xmod:Redirect> template tag. This tag enables you to use either HTTP GET or POST to redirect the user and send data between templates on any pages.

Here’s an Example:

<xmod:Redirect Text="Purchase" Target="http://mysite.com/purchase.aspx"> 
	<Field Name="pid" Value='[[ProductId]]' /> 
</xmod:Redirect> 

The above code creates a link and uses the default POST method to send a field called ProductID from the database record to the page purchase.aspx.

At the other end, you might have a template which is expecting this product ID parameter. This template would use the Request Token [[Form:parameterName]] to collect the parameter.

For example, your template on the purchase page might look something like this:

<xmod:Template>
	<HeaderTemplate>
		<h1>Show the product ID</h1>
		<p> Value of POST Parameter 'PID' is '[[Form:pid]]'</p>
	</HeaderTemplate>
</xmod:Template>

If you wish to use GET instead of POST and pass the parameters on the query string,you would only have to change the <xmod:Redirect> tag to something like this:

Using Get:

<xmod:Redirect Method="get" Text="test" Target="http://mysite.com/purchase.aspx?pid=10020">
</xmod:Redirect>

However, of course you are unlikely to want a hard coded parameter and will have to do the following to pass it into the url.Here I have used the JOIN function to enable me to pass the PID field onto the query string.

Example using the JOIN function:

<xmod:Redirect Method="get" Text="test" Target='[[Join("http://mysite.com/home.aspx?pid={0}",[[pid]])]]'>
</xmod:Redirect>

Of course you can simply add more fields onto the url with additional replacements.

Adding more Fields into the url:

<xmod:Redirect Method="get" Text="test" Target='[[Join("http://mysite.com/purchase.aspx?pid={0},{1},{2}",[[pid,]],[[title]],[[country]])]]'>
</xmod:Redirect>

To receive url parameters in your templates, you must use the request Token for url parameters.

Using the Request Token for Url parameter:

<xmod:Template>
	<HeaderTemplate>
		<h1>HTTP Request Information</h1>
		<p>Value of URL Parameter 'param1' is '[[Url:param1]]'</p>
	</HeaderTemplate>
</xmod:Template>

Although I have demonstrated how to use the redirect tag, you can also use simple HTML for your links and pass in url parameters without using the join function.

For example:

<a href="http://www.flicka20.com?title=[[title]]&pid=[[id]]">The Link</a>

I hope we've now gotten a decent grasp of how we can pass data between templates on various pages.

But what if we want to pass data between templates within the same module?

The feature of XMod Pro allows us to quickly and easily demonstrate one-to-many or one-to-one data relationships on a page. For these kinds of scenarios, we can use the <xmod:CommandLink> tag. This tag is a very powerful feature of XMod Pro. With it, you can send data and call SQL on any number of templates with a single click. I shall not reproduce the command link example here but if you want an application that shows subsets of data when a link or image is clicked you must use this method.

Since the command link method enables you to load other template data sources, there is potentially a lot that can be done with it. For example, if you were to use a stored procedure in your target template, there is no reason why the link clicked should not perform updates, inserts, or deletes as well as selects. I am looking forward to exploring these possibilities at a later date.

With regard to Forms, things are similar to templates. However, with a form, you usually want to send data on submit. In that event you would use an add or update button.

For example:

<AddButton id="srchButt" cssClass="searchDocsButt" text="Search Library" 
Redirect='[[Join("http://www.mysite.com/docsearch.aspx?title={0}&doctypeID={1}",[[title]],[[dtid]] )]]' RedirectMethod="get"> 
</AddButton>

This form <AddButton> sends the user to a search page while passing some parameters onto the query string. On the target page there is a list that accepts the url parameters and filters the list by passing them into the SQL. If you wanted these parameters hidden from the user you might use RedirectMethod=Post and not include the query string data. In that event the form fields would all be posted to the target page.

If you wish to collect parameters in forms, you can use the same request tokens discussed above.

I hope that if you are new to XMod Pro, you can now see the immense power that this tool gives you in creating applications for your DotNetNuke web site. Once you are able to pass data to and from pages using XMod Pro, you can start to think about communicating with other web sites on the internet. For example you might have an associate site that wants to allow guests to view data on one of their pages. You can post some connection details from an XMod Pro form to a page written in PHP. The PHP application then verifies the user and allows instant access. The possibilities are huge.

Happy developing!

Gus