表单提交后的空页面(PHP& Javascript)

时间:2015-02-18 15:14:51

标签: php email

我有一个表单脚本,在提交后发送电子邮件。 javascript在提交后删除了表单。

但是当我提交表单时,它会显示空的.php文件。

继承我的index.html代码:



<!--Here is container with email subscription-->
<div class="container-fluid yellow-container bg-mail">
	<div class="row-fluid">
		<div class="span12">
		<h2>Laat hier je email adres achter, zodat wij weten dat je van de partij bent</h2>
		<p>Deze uitnodiging geldt voor jou en een relatie!</p>       

<form action="save.php" id="subscribe-form" method="post" name="subscribe-form">    
<input type="email" name="email" placeholder="Hier je emailadres" id="email" class="email required">                   
<button class="btn btn-inverse" id="submit" type="submit" value="Subscribe">Count me in!</button>
</form>            
         
</div>
</div>
</div>
&#13;
&#13;
&#13;

save.php代码:

&#13;
&#13;
<?php
if (isset($_POST['email']))  {
  
  //Email information
  $admin_email = "marco@daretodesign.nl";
  $email = $_POST['email'];
  //send email
  mail($admin_email, "Inschrijving via Dukdalf", $email . " " . "heeft zich ingeschreven via de website", "Van:" . $email);
}
?>
&#13;
&#13;
&#13;

javascript代码:

&#13;
&#13;
//Subscribe Form


if($('#subscribe-form').length && jQuery()) {
  
    $('form#subscribe-form').submit(function() {

      $('form#subscribe-form .error').remove();

      var hasError = false;

      $('.required').each(function() {
        if(jQuery.trim($(this).val()) === '') {
          var labelText = $(this).prev('label').text();
          $(this).parent().append('<div class="error">Vul a.u.b. uw email in.'+labelText+'</div>');
          $(this).addClass('inputError');
          hasError = true;
        } else if($(this).hasClass('email')) {
          var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
          if(!emailReg.test(jQuery.trim($(this).val()))) {
          var labelText = $(this).prev('label').text();
          $(this).parent().append('<div class="error">Vul a.u.b. een geldig email in.'+labelText+'</div>');
          $(this).addClass('inputError');
          hasError = true;
          }
        }
      });

      if(!hasError) {
        $('form#subscribe-form input.submit').fadeOut('normal', function() {
          $(this).parent().append('');
        });
        var formInput = $(this).serialize();
        $.post($(this).attr('action'),formInput, function(data){
          $('form#subscribe-form').slideUp("fast", function() {
            $(this).before('<div class="error">Bedankt voor het inschrijven!</div>');
          });
        });
      }

      return false;

    });  
&#13;
&#13;
&#13;

提前感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

它显示了你的空白php页面,因为你发送电子邮件之后应该将用户重定向到某个地方,可能是:

header('Location: http://www.example.com/');
exit;

此致 马塞洛