0

I need to make a form submission. At the moment I have created a post with has the URL...

http://localhost:8888/japan/quiz/

... and includes a form with the following html:

<form id="quiz" action="http://localhost:8888/japan/grade.php" method="post">
<radio buttons>
</form>

The grade.php form is my main folder (child theme folder), but if I press submit I just get a 404 page. I would like to know:

  • (1) Where do I need to place the grade.php file in my child-theme directly (or where does the action link need to point to)
  • (2) What do I change the action URL to so that I don't need to alter the html when the site goes live?

Thank you!

1 Answer 1

0

You may want to make sure you are creating a brand new page template for this. http://www.wpbeginner.com/wp-themes/how-to-create-a-custom-page-in-wordpress/

Sve the template in your Child Theme folder

In this template, place you form code where you want it to display. In the tag, change it to this:

<form id="quiz" method="post">

Also, you should add your grade.php code in here as well. Create a condition to see it the form is being submitted like so:

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    enter grade.php code here
} else {
    show form
}

Create a new page and assign it the template your just created. It is probably set to default at the moment.

Save the page and click the visit page link. Tryout the new form and see if it is working.

You should also grasp this concept for submitting data using a form on WordPress: https://codex.wordpress.org/WordPress_Nonces

1
  • Thanks for the prompt reply. Given that I will want to create multiple quizzes I'm not sure I can use if ($_SERVER['REQUEST_METHOD'] == 'POST') as that would be true for them all.
    – Gecko Boy
    Oct 16, 2016 at 4:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.