24/7 Support: 800.608.6482

Videos

Try our new AI assistant by clicking the chat icon in the lower right corner.

Developer Videos

Videos | Working with Post and Get Parameters

ver. 9.0 and later

Video Transcript

One really common thing you’ll do as a web developer when working with Miva Merchant is working with parameters, both in the url which would be an http git or a form post where you have a form that submits to a Miva page and passes in inputs, either as hidden inputs or other inputs within the form. The great part about Miva is it makes it very very easy. It does all the heavy lifting for you. It will process all the parameters that get passed in and make them accessible to you as global variables. It will always have the same name. So for example, at the end of a Miva url if you added &name=Brennan Miva will automatically parse that to a global variable called g.name and the value will contain Brennan. We’re going to do some examples to illustrate this here shortly.

So let’s get parameters or parameters passed in the url, well the same thing is true with post parameters. Any form with an action is a Miva page. Any parameters you pass either as a hidden input or just as a regular inputs within the form, Miva will automatically parse them out and create them as global variables. This is a very nice feature of Miva Merchant and makes it a pleasure to work with all parameters.

The last thing I want to say is don’t forget to encode the output, encode your entities. Anytime you’re taking user input such as from a url or from a form post, if you’re going to do anything with that value like output it to the screen, you want to make sure that it’s encoded. This will prevent cross sight scripting attacks, where someone is submitting malicious javascript code to try and execute on your page. An easy way to protect against this is always use &mvte, which stands for entity encoding, as the prefix for your variable. Let’s take a look at some examples to illustrate this concept.

Here I am back at the Miva Merchant storefront. You’ll notice the url is mm5/merchant.mvc which is the default url for Miva Merchant. I want to add some parameters. So if I do ?name=brennan and hit enter, nothing happens. However, if I want to access that variable, I can get to it because Miva automatically converts it to a global variable. Let me jump back to the Miva Admin. I’ll go to the storefront page. So here under Content I can put &mvte: so it’s entity encoded. Then global and then the name of the url parameter that I created. So here I used name and semicolon. So when I hit update and go back to the front end and hit refresh, you’ll see my name now appears on the page. Now we can change this value to Miva and hit enter and it updates on the page. So any value we put in there, Miva automatically parses that, turns it into a global variable with the same name and allows you to use it on any page within the same store. This is very powerful and very flexible. Now say I want to add a second parameter. Let’s add &location=california and hit enter. You’ll see the name still displays but my location doesn’t. Now we can fix that by coming back to the Miva Merchant Admin, coming down here, I’m just going to copy this, add a break, and change it to location. Now when we go back to the front end of the store and hit refresh, I now have California displaying.

This same concept works for post parameters. I’m going to jump back to the Miva Merchant Admin and I’m going to go to the product page. So here I’m going to jump down to the product display layout and we’ll see this is the form that gets submitted when the add to cart button is pressed. Here’s the button down here and there’s a bunch of hidden inputs that get passed in the form submit. Let’s say we want to add our own. I’m going to copy one that already exists and paste it in. Here I’m going to change the name to custom variable and I’m just going to hardcode the value to “This is a test.” So I’ll hit update and go back to the front end, find a test product here, I’m going to inspect element on the Add to Basket button because I hardcoded this into the product page, it should show up for every single product. And here it is, custom variable with a value of “This is a test.” So what we need to do is, the page this form submits to, we want to output that variable to the screen. We can see that by looking at the form action, so the form action submits to Screen=BASK, which is the basket page. I’m going to go back to the Miva Admin and go to the BASK page and in the header section I’m going to put &mvte:global because all post parameters get posted as global variables, and the name I gave it which was custom_variable and then a semicolon. So this should output in the header. I’m going to update the page and then go back to the front end and hit refresh and now when I click Add to Basket you’ll see my product was added to the basket, but here in the header of the page here is my hidden input that I created, “This is a test.” So that worked exactly as we’d expect.

Miva Merchant uses both post and get parameters extensively. The parameters are used to define what screen is being displayed, what action is being taken and what category and what product to display. This is a critical concept to understand and will take you a long way in working with Miva Merchant.






Looking for Developer Docs?

We have a whole section for that, including: Developer Training Series, Template Language docs, Module Development tutorials and much, much more.

Head to the Developer Section

This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.

Accept

Copyright © 1997 – 2024 Miva®, Miva Merchant®, MivaPay®, MivaCon®, Camp Miva®, Miva Connect®, Miva, Inc. All Rights Reserved.