Jump to content

redirect after correct form input


senca99

Recommended Posts

hey,

I'm working on a contact form. The form is being checked on correct values. If not completed correctly, the form shows again with a warning at the wrong or forgotten fields and the right fields remain fild in. After submitting with correct inputdata, there is a message shown in the same page saying "thank you, we'll contact you as fast as possible,...". But I would like to redirect the page to the homepage about 5 seconds after the message is being shown.

 

This is the form header part:

 

<form method="post" action="' .$_SERVER['REQUEST_URI'] . '" />

 

How can I make this form say "thank you" when the values are right (in the same page or another, that doesn't really matter) and then make it jump to the homepage again?

 

thanks in advance

Link to comment
Share on other sites

If the validation is done before any content is displayed, use the PHP header().

 header('Location: thankyou.php'); exit; 

Put that after all form validation is passed and correct and all processing is done.

 

If the validation is done after content is displayed you can use the about Javascript or a Meta Refresh.

 

Regards, PaulRyan.

Link to comment
Share on other sites

I've pasted the contactpage code because I don't know how to 'fix' it. The thank you message is shown inside the div where the form was present, just to give some info.

 


<?php

include('header.php');

?>



<div id="contentainer">	

<div id="linkerbalk">

</div>



<div id="content">

<br />





<h1>Contacteer ons</h1>





<p>

Kinder-en jeugdschoenen Indy<br />

Postweg 126 B1<br />

1602 Vlezenbeek<br />

Tel: 0032/02/460.22.60<br /><br />

Voor vragen of opmerkingen kan u onderstaand contactformulier invullen. Een kopie zal naar uw e-mailadres gestuurd worden.

</p>





<table>

<tr>

<td>

<?php

   $naam='';

   $vnaam='';

   $mail='';

   $onderwerp='';

   $bericht= '';

   

	$mail_ontv = 'svensegers88@gmail.com';



 // Speciale checks voor naam en e-mailadres wordt gedaan als we het form submitten

 if ($_SERVER['REQUEST_METHOD'] == 'POST')

	   {

	$naam=$_POST['naam'];

	$vnaam=$_POST['vnaam'];

   $mail=$_POST['mail'];

   $onderwerp=$_POST['onderwerp'];

   $bericht= $_POST['bericht'];

   

    // naam controle

   		 if (!ereg('^[ a-zA-Z-]+$', $_POST['naam']))

       		 $naam_fout = 1;

    // voornaam controle

   		 if (!ereg('^[ a-zA-Z-]+$', $_POST['vnaam']))

       		 $vnaam_fout = 1;

    // e-mail controle

  			 if (function_exists('filter_var') && !filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL))

            $email_fout = 1;

    // onderwerp controle

   		 if (!ereg('^[ a-zA-Z-]+$', $_POST['onderwerp']))

       		 $onderwerp_fout = 1;

    // bericht controle

   		 if (strlen($bericht )<20)

       		 $bericht_fout = 1;

    // antiflood controle

   	if (!empty($_SESSION['antiflood']))

   		 {

        $seconde = 20; // 20 seconden voordat dezelfde persoon nog een keer een e-mail mag versturen

        $tijd = time() - $_SESSION['antiflood'];

        if($tijd < $seconde)

            $antiflood = 1;

   		 }

		}





$naamerror='';

$vnaamerror='';

$mailerror='';

$onderwerperror='';

$berichterror='';

// Kijk of alle velden zijn ingevuld - naam mag alleen uit letters bestaan en het e-mailadres moet juist zijn, wordt gedaan als er op submit geklikt word

if (($_SERVER['REQUEST_METHOD'] == 'POST' && (!empty($antiflood) || empty($_POST['naam']) || !empty($naam_fout) || empty($_POST['vnaam']) || !empty($vnaam_fout) || empty($_POST['mail']) || !empty($email_fout) || empty($_POST['onderwerp']) || !empty($onderwerp_fout) || empty($_POST['bericht']) || !empty($bericht_fout))) || $_SERVER['REQUEST_METHOD'] == 'GET')

{

    if ($_SERVER['REQUEST_METHOD'] == 'POST')

    {

    	  if (!empty($naam_fout))

    	  		$naamerror='<tr><td></td><td><img src="warning.png" alt="warning" width=12 height=12 />  <font size = 3px>U vulde geen of een foute naam in</font></td></tr>';

    	  if (!empty($vnaam_fout))

    	  		$vnaamerror='<tr><td></td><td><img src="warning.png" alt="warning" width=12 height=12 />  <font size = 3px>U vulde geen of een foute voornaam in</font></td></tr>';

    	  if (!empty($email_fout))	

    	  		$mailerror='<tr><td></td><td><img src="warning.png" alt="warning" width=12 height=12 /> <font size = 3px> U vulde geen of een onjuist e-mail adres in</font></td></tr>';

		  if (!empty($onderwerp_fout))

	  		$onderwerperror='<tr><td></td><td><img src="warning.png" alt="warning" width=12 height=12 />  <font size = 3px>U vulde geen onderwerp in</font></td></tr>';

	  if (!empty($bericht_fout))

	  		$berichterror='<tr><td></td><td><img src="warning.png" alt="warning" width=12 height=12 />  <font size = 3px>U vulde geen bericht in</font></td></tr>';

			    }

        

  // HTML e-mail formlier





  echo '<form method="post" action="' .$_SERVER['REQUEST_URI'] . '" />

	  



  

  	   

      <table>

      '.$naamerror.'

      <tr><td><label for="naam" font-family="Monotype Corsiva">Naam:</label></td>

      <td><input type="text" size=40 id="naam" name="naam" value="' .$naam. '" /></td></tr>

      '.$vnaamerror.'

      <tr><td><label for="voornaam">Voornaam:</label></td>

      <td><input type="text" size=40 id="vnaam" name="vnaam" value="' .$vnaam. '" /><td></tr>

      '.$mailerror.'

      <tr><td><label for="mail">E-mailadres:</label></td>

      <td><input type="text" size=40 id="mail" name="mail" value="' .  $mail . '" /></td></tr>

      '.$onderwerperror.'

      <tr><td><label for="onderwerp">Onderwerp:</label></td>

      <td><input type="text" size=40 id="onderwerp" name="onderwerp" value="' . $onderwerp . '" /></td></tr>

      '.$berichterror.'

      <td><label for="bericht">Bericht:</label></td>

      <td><textarea id="bericht" name="bericht" rows="8" style="width: 340px;">' . $bericht . '</textarea></td>

      <tr><td></td><td><input type="submit" name="submit" value=" Versturen " /></td></tr>

      </table>



  </form>';

   

}

// versturen naar

else

{      

  // set datum

  $datum = date('d/m/Y H:i:s');

    

  $inhoud_mail = "===================================================\n";

  $inhoud_mail .= "Ingevulde contact formulier " . $_SERVER['HTTP_HOST'] . "\n";

  $inhoud_mail .= "===================================================\n\n";

  

  $inhoud_mail .= "Naam: " . htmlspecialchars($_POST['naam']) . "\n";

  $inhoud_mail .= "Voornaam: " . htmlspecialchars($_POST['vnaam']) . "\n";

  $inhoud_mail .= "E-mail adres: " . htmlspecialchars($_POST['mail']) . "\n";

  $inhoud_mail .= "Bericht:\n";

  $inhoud_mail .= htmlspecialchars($_POST['bericht']) . "\n\n";

    

  $inhoud_mail .= "===================================================\n\n";

  

  // --------------------

  // spambot protectie

  

  $headers = 'From: ' . htmlspecialchars($_POST['naam']) . htmlspecialchars($_POST['vnaam']) . ' <' . $_POST['mail'] . '>';

  $headers = stripslashes($headers);

  $headers = str_replace('\n', '', $headers); // Verwijder \n

  $headers = str_replace('\r', '', $headers); // Verwijder \r

  $headers = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $headers)); // Slashes van quotes

  

  $_POST['onderwerp'] = str_replace('\n', '', $_POST['onderwerp']); // Verwijder \n

  $_POST['onderwerp'] = str_replace('\r', '', $_POST['onderwerp']); // Verwijder \r

  $_POST['onderwerp'] = str_replace("\"", "\\\"", str_replace("\\", "\\\\", $_POST['onderwerp'])); // Slashes van quotes

  

  if (mail($mail_ontv, $_POST['onderwerp'], $inhoud_mail, $headers) && mail($_POST['mail'], $_POST['onderwerp'], $inhoud_mail, $headers))

  {	

  		



      // zorg ervoor dat dezelfde persoon niet kan spammen

      $_SESSION['antiflood'] = time();

      

      echo '

      

      <p>Bedankt voor het invullen van het contactformulier.<br /> We zullen zo spoedig mogelijk contact met u opnemen.</p>';

     

         }

  else

   		   {

      echo '      

      <p><b>Onze excuses.</b> Het contactformulier kon niet verzonden worden.</p>';

  }

}



?>

</td>

<td>

<iframe width="375" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" align="right" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=vlezenbeek+postweg+126&aq=&sll=37.160317,-95.712891&sspn=34.778245,79.013672&ie=UTF8&hq=vlezenbeek+postweg+126&hnear=&radius=15000&ll=50.807956,4.232348&spn=0.071946,0.071946&output=embed"></iframe><br /></small>



</td>

</tr>

</table>







</div>



<div id="rechterbalk">

</div>

<div id="footer">

</div>

</div>	

<iframe width="350" height="275" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" align="right" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=vlezenbeek+postweg+126&aq=&sll=37.160317,-95.712891&sspn=34.778245,79.013672&ie=UTF8&hq=vlezenbeek+postweg+126&hnear=&radius=15000&ll=50.807956,4.232348&spn=0.071946,0.071946&output=embed"></iframe><br /></small>





</div>





</body>



</html>



Link to comment
Share on other sites

Consider utilizing a simple link to allow them to continue.

 

It is VERY common for people to be distracted while using a computer. An office worker has an associate come up or they need to answer a phone call. Then when they look back at the screen "Duh?". 

 

Unless there is a critical need to redirect (ie "some conditional statement requires immediate action") it is preferred to allow the user to to maintain some 'illusion' of control.

 

Just my opinion.

(AND as stated in the previous posts - header redirects MUST occur BEFORE ANY output to the browser.)

 

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.