Reputation: 152
I have a custom php file (myform.php) inside my theme folder that contains custom form with behavior defined in javascript. I've created a new page in wp dashboard, and I've assigned MyForm as page template. There is a lot of custom logic regarding that form. This form calculates something based on your specificiation, and it is supposed to go to stripe and charge your credit card. At first, I've created a model in javascript and used it to fill that form with data. Now I want to do two things:
Which is the best way to achieve that, and how to do it? Should I place my methods in functions.php, or wp-ajax.php(NOTE: user is not going to be logged in) or myform.php ?
Please state your opinion, pros and cons, and provide me with example method that returns "Test" string. I'm having problems with stepping into method with postman.
Upvotes: 1
Views: 595
Reputation: 378
1st advice: Don't touch wp-ajax.php
, you should only edit files in your theme (folder).
funtions.php
vs. myform.php
: I'd put the template (html) into myform.php
and the methods in some other file. It could be functions.php
, but I'd use another file and include that later (e.g. in your functions.php
). This way you won't end up with a crowded functions.php
in the end. Your .js code should be in seperate files too - just my opinion ;-)
Upvotes: 1
Reputation: 9
Is this a problem to achieve a ajax post to your php? Because if you want to post to another file and return information without reloading the page this is the best way to achieve it.
I think you should put your function in the file which will be used to receive the ajax post. So you can calcute your information and return information if needed.
I hope this is the solution you were looking for.
Upvotes: 0