Forum

Thread tagged as: Question, Problem, PayPal

Paypal Shop Products in A Form

Hi, I'm looking for a bit of help getting Paypal shop products into a submit-able form. I want to programatically add the products into the form in the form template. Is there any documentation you know of that could help me with this ? Thanks dylan

Dylan Rynhart

Dylan Rynhart 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Where does the form go, and what does it do?

Sorry, Thanks, I'm trying to make an application form, so I'd like the customer to submit the form with the details of their application including the product they want to purchase in the forms responses section.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok. The what templates are parsed means that content from the database (like products in this case) gets parsed before the form field tags. So you can actually do this:

<perch:input type="select" options="<perch:content id="product_opts" />" />

Ok, so... Is there a way to loop through all the products ( within a form template ) and display each product as a checkbox or select option ? Thanks so much for your help.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You'd need to get your products into a variable out in the page. Then use PerchSystem::set_var() to pass that into the form template.

Ok, That's cool, please excuse my ignorance but.. how do I then loop through the array to print the form elements ?

Sorry, my brain is working now, I see how the select box is done without a loop, but in the case of creating a checkbox for each product ? Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Checkboxes might be more tricky. In fact, I'm not sure I can think of a way to do that with checkboxes.

I was about to reply this morning saying that I would resign myself to using Select boxes but I eventually found a solution. I prepared all the HTML <perch:form stuff into a php file that I assigned to a var and used the

PerchSystem::set_var('products')

and

<perch:content id="products" html="true" />

But the form checkboxes wouldn't submit, so .... I ended up writing the var to a html template file and including the html using:

<perch:template path="content/competitions.html" />

I should really work out some way for the file not to be constantly recreated, but for now this works. It would be amazing for the first option to work, but I can see why it doesn't. Thanks for your help. Dylan

Drew McLellan

Drew McLellan 2638 points
Perch Support

The fields need to be in the template when the form is parsed, which they're not if they've ben inserted as a string at runtime.