Jump to content

Foxycart - Inject field data


Peter Knight
 Share

Recommended Posts

I have two basic text fields called Product and Price.

According to FoxyCart docs, I can manually create a URL as follows which will add a Picture Frame worth 100 dollars to my cart.

<a href="https://YOURSTORE.foxycart.com/cart?name=PictureFrame&price=100">Add picture frame</a>

Is there a way to swap out the product and price for the values in my fields? I've tried the following but it never converts my fields into actual data

<a href="https://YOURSTORE.foxycart.com/cart?name=<?php echo $page->product; ?>&price=<?php echo $page->price; ?>Add picture frame</a>

I

There are some errors in the formatting above but you get my thinking. Typing on ipad

Link to comment
Share on other sites

@Peter,

You should pass the values from $page->product through a url sanitizer. If there are any spaces in the product field you'll get a dud url doing it like that.

$url = wire()->sanitizer->url($page->product);

You could pass the price field through the sanitizer too - no harm in that.

  • Like 1
Link to comment
Share on other sites

I don't know if that will fix your exact problem - it might if your product field has a space in it.

I do know that the way you are outputting a user-supplied field as part of a URL could generate invalid URLs. For example, If a user ever entered anything other than a-z, A-Z, 0-9, _, -, ~ or . in your product field you could find yourself with a potentially troublesome url - especially if that field had an '&' in it. If that were the case and you keep constructing the urls like that you'll find there's an extra get parameter for each '&' in your product field; probably not what you want.

More on wikipedia.

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...