Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-07-12 22:56:22

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 299
Website GitHub Twitter

Auto-submitting a form

I need to add items to my yab_shop cart programmatically, and am stuck.

In an iOS AR app, a potential customer views a 3D product model in their living room. They opt to purchase the product, and tap through to a TXP website running yab_shop: myshop.com/ar-checkout?product=SKU123,SKU456,etc.

My approach to date has been to grab the various articles with matching SKU custom fields, and then use Javascript to sequentially submit each article’s ‘add-to-cart’ link.

All behaves normally if I manually click an ‘add to cart’ link (the page reloads with the cart message shown), but if I use Javascript i.e. form.submit() the page reloads, but yab_shop has ignored the request.

I can’t find anything in yab_shop code that might be the culprit, so I think there must be a gap in my understanding of the broader processes at work. Yab Shop uses $_SESSION to instantiate the cart – could this be preventing submission via Javascript?

…or is there a simpler way of achieving the same thing?

Advice is welcome! :)

Last edited by giz (2018-07-12 22:59:21)

Offline

#2 2018-07-14 18:17:45

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 299
Website GitHub Twitter

Re: Auto-submitting a form

Bump!

Offline

#3 2018-07-20 10:30:58

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,447
Website GitHub

Re: Auto-submitting a form

Very odd. Submitting the form via JavaScript should do the same thing as clicking the ‘submit’ button.

Is there anything in the browser web inspector that might give you a clue as to what’s going on? e.g. compare the inspector payload params when submitted via clicking the button vs programmatically submitting? The session in yab_shop is just to keep the cart contents in memory across page requests so shouldn’t have any bearing on how the form is submitted.

Bizarre.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2018-07-20 18:44:34

giz
Member
From: New Zealand
Registered: 2004-07-26
Posts: 299
Website GitHub Twitter

Re: Auto-submitting a form

Thanks Bloke.

I tried all kinds of tests; inspector payload remained the same. Zo-bizzare: a com_connect form on the same page submitted via javascript as expected.

I gave up on this one! I changed the workflow, making my auto-submit problem moot.

Offline

Board footer

Powered by FluxBB