Search Articles

Sort By

Article Categories

Authors & MVPs

Kelly Ford

Introducing DNNDev University

The new DNNDev University doesn't have a winning football team. It is built on people - you and I and everyone who uses DotNetNuke and XMod Pro.


How To Send Data Between XMP 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:

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:

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

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.

Of course you can simply add more fields onto the url with additional replacements like this:

To receive url parameters in your templates you must use the request token for url parameters, For example:

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,

I hope we have now got 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. So, for example:

This form add button 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.

In 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!


Comments & Ratings

    (Ratings: 9   Avg: 2.22)
Rate It!
Share It!