The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Pre-Populating Custom Fields

daneastleydaneastley Member
in General edited November 2012

I'm looking to find out whether I can pre-populate a custom field on the checkout page. I can stick custom fields on the page, and of course fill them, and get them to appear in the custom fields in the transaction. But I'd like to pre-fill them.

The premise behind this is as follows:
1. Cart page sits on our site and loads the cart in using JSONP (straight out of the example in the docs)
2. The checkout button on here fires the user straight into the checkout page (e.g. missing the /cart page).
3. This checkout button can (as per the docs) pre-populate most of the fields (via POST params or GET using the querystring).

The idea is that I'd like to pass an reference into the order.

Any help on this would be awesome. Thanks.
  • fc_adamfc_adam FoxyCart Team

    You could pass the reference into the json as a session attribute, and then on your checkout, on page load, pull that session attribute from the json and put it in it's relevant custom field.

    We do have a ticket for expanding our prepopulation to allow for custom fields, but it hasn't made it up the list yet.
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Ha! I ran into the exact same issue today. I was pre-populating form fields from the querystring but the custom fields wouldn't go. I used javascript to do it:
    reset_value = unescape(getQueryVariable("MY_QUERY_VAL")).replace(/\+/g, " ");
    function getQueryVariable(variable) {
    	var query =;
    	var vars = query.split("&");
    	for (var i=0;i<vars.length;i++) {
    		var pair = vars[i].split("=");
    		if (pair[0] == variable) {
    			return pair[1];
  • Hey Guys,

    Thanks for the quick response.

    Sounds promising. Can I set a session attribute after a product is added to the cart? The reference that needs to get added in is only available once the user kicks off the checkout process (so the products are already in the basket).

    Looks good - although if the user submits the form, and an error is encounted (missing field for example), the value will no longer be in the querystring and as the form field can't be pre-filled (server side), then the value will be lost - I haven't tested to see if this happens yet though.

    Thanks again.
Sign In or Register to comment.