Jump to content

form post to self and isset


Philwn

Recommended Posts

Hi all,

Hoping someone can help with what i would guess is a very simple problem.

 

I have the following code which is suppose to display a form. the form posts to itself and uses isset and if the form has been posted it doesnt display the form.

 

		if (isset($_POST['submit'])) {

	echo "question submitted successfully";
	}
	else {
          echo '<form method="post" name="qanda" id="qanda" action="http://' . $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '">';
          echo '<p><label for="name">Name</label> <input type="text" id="name" /></p>';
          echo '<p><label for="e-mail">E-mail</label> <input type="text" id="e-mail" /></p>';
          echo '<p><label for="Question">Question</label>  <textarea rows="6" id="question"></textarea></p>';
          echo '<p class="submit"><input type="submit" value="Submit" /></p></form>';
	  }

 

this currently doesnt work.

 

Extra things you might need to know is that this script/form is an included file in a dynamic site which also uses the rewrite module which is why I am using http://' . $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] just incase that makes a difference.

Link to comment
Share on other sites

hmm not sure if I have misunderstood your reply but this seems to have stopped the file being included aswell as two other files that are included after this section.

 

        <?php 
	if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit']) {

	echo "question submitted successfully";
	}
	else {
          echo '<form method="post" name="qanda" id="qanda" action="">';
          echo '<p><label for="name">Name</label> <input type="text" id="name" /></p>';
          echo '<p><label for="e-mail">E-mail</label> <input type="text" id="e-mail" /></p>';
          echo '<p><label for="Question">Question</label>  <textarea rows="6" id="question"></textarea></p>';
          echo '<p class="submit"><input type="submit" value="Submit" /></p></form>';
	  }
	  ?>

Link to comment
Share on other sites

The if() statement is missing a closing ) and produces a fatal parse error, but you should have discovered that when you put the code into your file and executed it on your development system (almost all of the code you see posted in a forum is NOT TESTED and could contain typos.)

 

You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_error set to ON in your master php.ini so that all the php detected errors will be reported and displayed.

Link to comment
Share on other sites

sorry I didn't spot the typo, I saw the close bracket  for the $_POST and thought it was the one for the if statement.

 

I do not have debugging on and am unaware of the location of the php.ini, I shall look into it now.

 

I am still having problems with this code not working though, the page displays correctly and calls the includes but when the form is posted it still brings up the form instead of "question submitted successfully".

 

Link to comment
Share on other sites

Actually this is true in the case of internet explorer if the Enter key is pressed instead of the submit button being clicked, for safe measure change the if statement to

 

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['name'])) {

 

also you need to add the following name tags to your form or it wont process at all when you add the processing features

 

          echo '<p><label for="name">Name</label> <input type="text" id="name" name="name" /></p>';
          echo '<p><label for="e-mail">E-mail</label> <input type="text" id="e-mail" name="email" /></p>';
          echo '<p><label for="Question">Question</label>  <textarea rows="6" id="question" name="question"></textarea></p>';
          echo '<p class="submit"><input type="submit" value="Submit" /></p></form>';

The $_POST name come for the name tags in the forms

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.