Jump to content

problems with form action


carinemaz

Recommended Posts

Hi all,I'm having problems displaying properly my pages once you hit the submit button on my form...Here is the code

<form class="form" action="message_rep.php" method="post">					<p><label for="nom">Nom :</label><input type="text" name="nom" size="30" /></p>			<p><label for="email">Email :</label><input type="text" name="email" size="30" /></p>			<p><label for="objet">Objet :</label><input type="text" name="objet" size="30" /></p>			<label for="message">Message :<br /><textarea rows="10" cols="40" name="message"></textarea> 			<p><input type="submit" value="Soumettre" class="input"  /></p> 	  </form>

<?php$nom=$_POST['nom'];$email=$_POST['email'];$objet=$_POST['objet'];$message=$_POST['message'];$message_bis= "Vous avez oublié de remplir : " ;if (empty($nom)) : 	$message_bis= $message_bis . " Nom";endif;if (empty($email)) : 	$message_bis = $message_bis . " Email";endif;if (empty($objet)) : 	$message_bis= $message_bis . " Objet";endif;if (empty($message)) : 	$message_bis= $message_bis . " Message";endif;if (empty($nom) or empty($email) or empty($objet) or empty($message)) :		echo "<script type='text/javascript'>\n";	echo "alert('$message_bis');\n";	echo "</script>";include('message.php');else :	$envoyer_vers='patricia@medipsy.com';	$delapartde='from: patricia@medipsy.com';	$contenu_message = 'Nom : '.$nom."\n".					'Email : '.$email."\n".					'Message : '.$message."\n";	mail($envoyer_vers, $objet, $contenu_message, $delapartde);	$message_bis= "Votre message a bien été envoyé. " ;	echo "<script type='text/javascript'>\n";	echo "alert('$message_bis');\n";	echo "</script>";include('index.php');endif;?>

Depending if you've filed the form correctly or not, you get redirected to a different page. If all fields are filed, you go back to the index, if not, back to the form page....In order to do that, I've put my include() in the if or else statement, but by consequence, when you hit submit, the popup window comes up with a blank page in the back, and for whatever reason, when you click ok, my content is no longer centered...I'd like my form page to stay up when the popup window comes up... And figure out why my content gets shifted to the left....Hope my explanations make sense?Any solutions?

Link to comment
Share on other sites

Is the order of the page you are echoing correct? You echo a javascript, but is it allowed at that location in the html?Maybe it is better to echo an entire page instead of only parts. Or, create the page in variables and acho it when the page is fully defined, so you know what exactly the order is :)

Link to comment
Share on other sites

Dan is correct, you are sending the javascript code before you send the actual page. You will want to send all of the page information, and display the javascript last (ideally, you will want the javascript to appear before the closing </body> tag, so you may need to indicate an error in message_rep.php, but have message.php or index.php check if an error occurred and actually send the javascript). This is the reason why both the page is blank and the content is misaligned - the browser doesn't know how to handle the javascript code coming first. If you want the popup over the page with the content already on it (not a blank page), send the page first, then send the javascript code.

Link to comment
Share on other sites

Thanks for your response.I am calling an entire page...The whole thing works fine if I just call one page... say the form page. But as soon as I put the "include" in the if statements to call two different pages, it bugs... I don't know how to do it any other way...

Link to comment
Share on other sites

Dan is correct, you are sending the javascript code before you send the actual page.  You will want to send all of the page information, and display the javascript last (ideally, you will want the javascript to appear before the closing </body> tag, so you may need to indicate an error in message_rep.php, but have message.php or index.php check if an error occurred and actually send the javascript).  This is the reason why both the page is blank and the content is misaligned - the browser doesn't know how to handle the javascript code coming first.  If you want the popup over the page with the content already on it (not a blank page), send the page first, then send the javascript code.

didn't see your reply...Will try changing the order, thanks!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...