I don't know what the heck the problem is with this form not working. The form is not to be sent anywhere. It's just a questionnaire for clients to fill/print out if they like, but I cannot get the results to post into the hidden div. What am I doing wrong? I installed a wordpress php plugin and other php echo's work, but not the POST thing. The HTML:
<form method="post">
<input type="text" placeholder="Your Name" name="yourname" />
<br /><br />
<input type="text" placeholder="Pet's Name" name="petsname" />
<br /><br />
<input type="text" placeholder="Pet's Birth Date" onfocus="(this.type='date')" onblur="(this.type='text')" id="date" name="petsbirthdate" />
<br /><br />
<strong>Pet's Sex</strong>: <input type="radio" value="Male" name="sex" id="Male" /><label for="Male">Male</label> <input type="radio" value="Female" name="sex" id="Female" /><label for="Female">Female</label>
<button type="button" class="button" onclick="show_output();">Display
Answers</button>
</form>
Pay no attention to the onclick handler on the button. I'm not including that JavaScript, but just know that the hidden div does show when the button is clicked. The PHP that returns no form results: Pay no attention to the PHP in brackets, that's the way it works in WordPress with the plugin.
<p class="data_answers">
<strong>Your Name:</strong> [php]echo htmlspecialchars($_POST['yourname']);[/php]</p>
<p class="data_answers">
<strong>Pet's Name:</strong> [php]echo $_POST['petsname'];[/php]</p>
<p class="data_answers">
<strong>Pet's Birth Date:</strong> [php]echo $_POST['petsbirthdate'];[/php]</p>
<p class="data_answers">
<strong>Pet's Sex:</strong> [php]echo $_POST['sex'];[/php]</p>
The PHP that will work (anywhere; I even placed it in the middle of, where the form answers should be, and it shows up. So why doesn't the other work?
[php] echo "Hello world!"; [/php]
Thank You! Tracy
P.S. Although you cannot see the PHP, but the actual page in draft is here: http://www.safarivet.com/behavior-conditions/
2 Answers 2
You should add the action attribute in the form tag
<form method="post" action="">
..leads back to the same page
1 Comment
Extending from Johannes answer, you can also use a number sign # or the global variable $_SERVER['PHP_SELF']
Either of these will work
<form method="post" action"">
<form method="post" action"#">
<form method="post" action"<?php echo $_SERVER['PHP_SELF']?>">
[php], but to write PHP code inline in html you write<?php echo 'TEST'; ?>. Does this fix your issue?