0

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>: &nbsp;&nbsp;&nbsp;<input type="radio" value="Male" name="sex" id="Male" /><label for="Male">Male</label>&nbsp;&nbsp;&nbsp;&nbsp;<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/

asked Jul 26, 2017 at 11:36
2
  • You've written the PHP tags as [php], but to write PHP code inline in html you write <?php echo 'TEST'; ?>. Does this fix your issue? Commented Jul 26, 2017 at 11:39
  • As I mentioned in my original post above: Pay no attention to the PHP in brackets, that's the way it works in WordPress with the plugin. Commented Jul 26, 2017 at 14:08

2 Answers 2

2

You should add the action attribute in the form tag

<form method="post" action="">

..leads back to the same page

answered Jul 26, 2017 at 11:55
Sign up to request clarification or add additional context in comments.

1 Comment

From what I have extensively read, you should NOT have an empty action tag. With it omitted, it validates and leads back to the same page as I want.
0

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']?>">
answered Jul 26, 2017 at 12:13

1 Comment

No, no, no to all. I have read a kazillion pages and the best validating method in use Today is NO action attribute at all if you want it to lead back to the same page. Besides, tried all that anyway. Without the action, I don't have page reload issues.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.