Page 1 of 1

Help reqd with form design

Posted: Sat Dec 17, 2011 1:17 pm
by Live24x7
Please help me with this simple form design -

For simplicity, lets say my form has 2 fields - name and email.
On submit, i want to do 3 things:

1) Send email
2) Insert into MYsql Db
3)redirect to a thankyoupage
(say thankyou.php)
I have no issues with 1 and 2 above, but when i try to redirect using header

Code: Select all

('Location: thankyou.php');
i get the - header already sent error

My form flow is somewhat like this

Code: Select all

<?php
 if (isset($_POST['submit'])) 
				{ 	
                              include (connect.php) // DB connect
				$rname= $_POST['rname']; 
                                  $remail= $_POST['remail']; 
				// some php form validation 
				//php to send email code
				// php to Insert into DB 
				header('Location: thankyou.php'); // - this is where i am getting stuck
					}}else {
					
					include_once ('header.php'); 

 ?>
 
			<!-- Form Code Start -->
			 <h2>Member Registration</h2> <br/>
				<form name="rform" class='form' action="'' method='POST' >
				<label>Name </label> <input type='text' name='rname' maxlength="20" /> <br/>
				<label>Email</label>  <input type='text' name='remail' maxlength="40" /><br/>
				<input class='button' type='submit' name='submit' value='SUBMIT TO JOIN'/>    
				</form>	<!-- Form Code Ends --> 		
<?php } ?>

I am now using a JS redirect to keep this form functioning but, i want to use php to redirect to thankyou page

Do i need to change the form structure ?

PLease advise. :roll:

Re: Help reqd with form design

Posted: Sat Dec 17, 2011 8:06 pm
by califdon
This is not a form design issue, it is simply a PHP issue. As you have found, if a script has sent anything at all to the browser (even a blank line or a linefeed character) then you cannot send a redirect header after that. The solution is to structure your script so that absolutely nothing is sent to the browser until you have (if you're going to) sent the redirect header. Since you haven't shown us any other code than you have, all I can tell you is that you need to think about the structure of your entire script and modify it to meet the above criterion.

Re: Help reqd with form design

Posted: Sun Dec 18, 2011 3:57 am
by Live24x7
thankyou califdon, will rework it out.