Odd Self Submitting Form Behavior

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Odd Self Submitting Form Behavior

Post by JakeJ »

I have a page, index.php that has an include file for the header, one for the side bar and one for the main body.

The include for the main body is a form and the form is self submitting. All of the form code is in the included file.

Each of my forms has a button that refers back to the other form (this is just a test so far).

Each time I click on the button, a . gets added to the end of my URL. http://localhost/template.php then it's http://localhost/template.php. then http://localhost/template.php.. and so on each time I click submit.

I'm not using $_GET[] at all so I just don't understand why it's happening. Everything works right but this is strange behavior.

Here's some code:

Code: Select all

//from the top of template.php
?php session_start();

if(isset($_POST['submit'])) {
		$include = $_POST['submit'];
}
Else {
	$include = "/includes/incl_index.php";
}
?>
//other html code omitted - no php
//from the body of the template.php
<div id="mainContent">
	<?php include($include); 
	echo $include; ?>
	</div>

Code: Select all

//from incl_index.php .. the entire contents
<h1>THIS IS A SUCCESFUL TEST</h1><br>
<FORM NAME = 'INDEXFORM' ACTION=<?php echo $_SERVER['PHP_SELF'];?>. METHOD=POST>
<input NAME = 'submit' type=SUBMIT VALUE='/includes/incl_submit_test.php'>
</FORM>

Code: Select all

//from incl_submit_test.php .. the entire contents
<h1>THIS IS A SUCCESFUL SUBMIT TEST</h1><br>
<FORM NAME = 'INDEXFORM' ACTION=<?php echo $_SERVER['PHP_SELF'];?>. METHOD=POST>
<input NAME = 'submit' type=SUBMIT VALUE='/includes/incl_index.php'>
</FORM>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Odd Self Submitting Form Behavior

Post by Christopher »

Code: Select all

<FORM NAME = 'INDEXFORM' ACTION=<?php echo $_SERVER['PHP_SELF'];?>. METHOD=POST>
There is a dot after you echo PHP_SELF. And you really should use the more modern XHTML style:

Code: Select all

<form name="INDEXFORM" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
(#10850)
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Odd Self Submitting Form Behavior

Post by JakeJ »

I've never worked with XHTML, can you give me an example?

Oh, and thanks for pointing out the extra period. <FACE PALM>
Post Reply