Where to add php code and how to pass data from JavaScript
-
Hi to everyone,
I have some questions regarding the best way to organise an online personal project of mine. I looked in several resources but could not really figure this one out.
I am using WordPress combined with ACF (Advance Custom Fields) so the user can generate a table that has a fixed amount of columns but the number or rows is variable. I have like 10 of this, they are products’ characteristics that relate to a product page.
In the front end the users can pick which of the previous products’ characteristics want to display, something similar to a comparator tool (e.g. http://youcompare.com.au/mobilephones/compare).
My guesses are:
1-I need to collect the user choice. Is it the best way to do so using JavaScript? All the extra functionality should be done via JavaScript (I guess jQuery is good too).
2-I need to pass the JavaScript collected choice to the PHP function that prints the function out. Is the best way to do this using AJAX?
3-I need a PHP (?) function that receives the user choice (via parameters I guess) and prints the function out.
Are all these steps correct?
About point 3 I have a couple of questions:
A-Is PHP suitable for doing this?B- Where should I define the function? Can I create a separate file in WordPress (eg. print-table.php) for only this function?
C-How do I then make my theme know that this function exists? (I know it is a basic stupid question but could not figure it out).
D-Can I display the changes (e.g. adding a new product to the comparison or removing a product from the comparison) without having to reload the page?
Thanks a lot for your time. I am sorry if this has been asked before but during my research I wasn’t able to figure all these out.
I am using a local installation of WP 4.3 and 4.4.4 of ACF.
Cheers,
Josep
The topic ‘Where to add php code and how to pass data from JavaScript’ is closed to new replies.