javascript - Redirecting to index.html after submit a form - How to show a message -


on form contact of site, when pressed submit button site open blank page (the php file), in order remove that, added

header("location: ../index.html"); 

to php file, works, mantains same page after submit data, instantaneous goes index.html, having code show message of success or failure message doesnt show up.

not sure why, because of method, saw many topics talking using ajax, find confusing me, must-use on site ? can me getting working site ?

the site on free host:

tential.co.nf

html:

    <!doctype html> <html>   <head>     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>     <script src="js/fixedbar.js"></script>     <script src="js/slider.js"></script>     <meta charset="utf-8">     <link href="http://fonts.googleapis.com/css?family=open+sans:400,300" rel="stylesheet" type="text/css">     <link href="styles.css" rel="stylesheet" type="text/css">     <title> layout </title>   </head>   <body>       <div class="header" id="top">       <img class="logo" src="img/logo.png">       <div class="menu">         <a href="#" class="current">home</a>         <a href="#tour">product tour</a>         <a href="#">pricing</a>         <a href="#">try</a>         <a href="#vision">vision</a>       </div>       <div class="move">         <div class="center">           <h1>move work forward!</h1>           <p>optential keeps team organized, connected, , focused on results.</p>         </div>       </div>       <div class="mail1">         <form action="form/form.php" method="post">           <h1>try now!</h1>           <input name="email" class="email" type="text" placeholder="enter email address ...">           <input type="submit" value="get started free">         </form>       </div>     </div>      <div class="mail2">         <form action="form/form.php" method="post">         <h1>try now!</h1>         <input type="text" placeholder="your email here...">         <input type="submit" id ="btn" value="get started free">         <a class="top" href="#top">top</a>       </form>     </div>       <div id="slider">         <div class="images">           <div class="controls">           <img src="img/3.png" alt="image-1" />           <img src="img/2.png" alt="image-2" />           <img src="img/1.png" alt="image-3" />           <img src="img/4.png" alt="image-4" />         </div>        </div>     </div>      <div class="barra2"></div>      <div class="mobile">       <div id="pc">         </div>        <div id="pctexto">        </div>     </div>      <div class="contact">       <div class="textocon">         <div>           <h1>optential</h1>           <p>a new management system<br>for new management paradigm!</p>         </div>       </div>       <form method="post" action="form/contactengine.php">         <div class="col1">           <h1>contact us!</h1>           <input type="text" name="name" size="50" placeholder="name"/>           <input type="text" name="email" size="50" placeholder="email"/>           <input type="text" name="subject" size="50" placeholder="subject"/>         </div>         <div class="col2">           <textarea name="message" rows="5" cols="70" placeholder="message..."></textarea>           <input type="submit" id="btn"value="send email"/>         </div>       </form>       <div class="info">         <div>           <h1>mail !</h1>           <p>rua andrade corvo, 242</p>           <p>sala 206</p>           <p>4700-204 braga</p>           <p>portugal</p>         </div>         <div>           <h1>call !</h1>           <a href="#"><p>+351 987654323</p></a>           <a href="#"><p>+351 987654323</p></a>           <a href="#"><p>+351 987654323</p></a>         </div>         <div>           <h1>email us! </h1>           <a href="#"><p>code@angel.com</p></a>           <a href="#"><p>code_hr@angel.com</p></a>           <a href="#"><p>code_support@angel.com</p></a>         </div>         <div>           <h1>join us! </h1>           <a href="#"><img src="img/facebook.png"></a>           <a href="#"><img src="img/gplus.png"></a>           <a href="#"><img src="img/twitter.png"></a>           <a href="#"><img src="img/instag.png"></a>         </div>       </div>     </div> <script src="js/slider.js"></script>   </body> </html> 

php:

    <?php  $emailfrom = "no-reply@site.com"; $emailto = "duarte.andrade@team.androidpt.com"; $name = trim(stripslashes($_post['name']));  $email = trim(stripslashes($_post['email']));  $subject = trim(stripslashes($_post['subject']));  $message = trim(stripslashes($_post['message']));   // validation $validationok=true; if (!$validationok) {   print "<meta http-equiv=\"refresh\" content=\"0;url=error.htm\">";   exit; }  // prepare email body text $body = ""; $body .= "name: "; $body .= $name; $body .= "\n"; $body .= "email: "; $body .= $email; $body .= "\n"; $body .= "subject: "; $body .= $subject; $body .= "\n"; $body .= "message: "; $body .= $message; $body .= "\n";  // send email  $success = mail($emailto, $subject, $body, "from: <$emailfrom>");  // redirect success page  if ($success){   echo "<script type='text/javascript'>alert('submitted successfully! contacting us')</script>"; } else{   print "<meta http-equiv=\"refresh\" content=\"0;url=error.htm\">"; }     header("location: ../index.html"); ?> 

you use meta refresh tag.

have php display page withy success message , include this:

<meta http-equiv="refresh" content="5; url=http://example.com/"> 

the "5" in content= seconds. set how long want display success message. also, set url= page want go next.

in specific case, try modifying code this:

if ($success){     echo "<script type='text/javascript'>alert('submitted successfully! contacting us')</script>";     echo '<meta http-equiv="refresh" content="0; url=http://example.com/">'; } 

the alert box keep refresh firing until alert box closed.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -