Jump to content

Recommended Posts

Posted

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

Posted

@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
Posted

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.

Posted

Quick update. If you're running the latest version of FoxyCart, embedding field values in FC links will work.

When I originally posted, I think FC was running a slightly older version. 

  • Like 1
  • 1 year later...
Posted

Hey Guys,

I got one more question about foxycart: How did you get your quantity value into the foxycart link?

Do you have a best practice for the &quantity=XX ?

Thank you!

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
×
×
  • Create New...