使用提交按钮清除输入

时间:2014-07-01 16:09:34

标签: javascript php html

从C#转换到PHP一点点,而不是看到我在这里做错了什么。

我想要的是当我点击提交按钮时 - 我希望发送电子邮件(就像它正在做的那样)但我希望输入文本字段清除用户之前输入的旧文本。

我想到的一种方法是在实际提交之前清除我的测试,这对我没什么帮助。

有关如何执行此操作的任何输入?

<?php
/*
 * Template Name: Contact
 * Description: Contact Us
  */
 get_header();
  ?>

 <div class="container">
 <div class="section group">
<div class="col span_2_of_2">
<h1> Contact Us <h1>
 <p style="font-size:16px"> Radiology Services LLC is located on the east side of   Evansville, IN off the Robert D. Orr Highway.</p>
<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3146.027108890167!2d-   87.45272299999999!3d37.953153!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x170f5925d75e6135!2s    Radiology+Services+LLC!5e0!3m2!1sen!2sus!4v1404175203674" width="100%" height="350px"    frameborder="0" style="border:0"></iframe>
</div>
<div class="col span_1_of_2" style="padding-left:40px;>
<?php

//response generation function

 $response = "";

 //function to generate response
 function my_contact_form_generate_response($type, $message){

 global $response;

 if($type == "success") $response = "<div class='success'>{$message}</div>";
 else $response = "<div class='error'>{$message}</div>";

 }

//response messages
$not_human       = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid   = "Email Address Invalid.";
$message_unsent  = "Message was not sent. Try Again.";
$message_sent    = "Thanks! Your message has been sent.";

 //user posted variables
 $name = $_POST['message_name'];
 $email = $_POST['message_email'];
 $message = $_POST['message_text'];
 $human = $_POST['message_human'];

 //php mailer variables
 $to = 'aje@gmail.com';
  $subject = "Someone sent a message from ".get_bloginfo('name');
   $headers = 'From: '. $email . "\r\n" .
 'Reply-To: ' . $email . "\r\n";

 if(!$human == 0){
   if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
   else {

  //validate email
  if(!filter_var($email, FILTER_VALIDATE_EMAIL))
    my_contact_form_generate_response("error", $email_invalid);
  else //email is valid
  {
    //validate presence of name and message
    if(empty($name) || empty($message)){
      my_contact_form_generate_response("error", $missing_content);
    }
    else //ready to go!
    {
      $sent = wp_mail($to, $subject, strip_tags($message), $headers);
      if($sent) my_contact_form_generate_response("success", $message_sent);
      else my_contact_form_generate_response("error", $message_unsent); 
    }
  }
}
}
  else if ($_POST['submitted']) my_contact_form_generate_response("error",    $missing_content);
?>
  <?php while ( have_posts() ) : the_post(); ?>
        <div class="entry-content">
          <?php the_content(); ?>



 <style type="text/css">
            .error{
              padding: 5px 9px;
              border: 1px solid red;
              color: red;
              border-radius: 3px;
            }

            .success{
              padding: 5px 9px;
              border: 1px solid green;
              color: green;
              border-radius: 3px;
            }

            form span{
              color: red;
            }

 .subBtn{
 width:100%;
  border-radius: 0px;
 background-color:#5bb75b;
 color:#FFFFFF;
  }
  .subBtn:hover{
  background-color:#408140;
  }
  .m{
 width:100%;
  border-radius: 0px;
 }
          </style> 
  <script language="javascript">
  fromreset()
  {
  myform.reset(); 

 document.myform.[textbox Id] = " "; 
 }
</script>


<form name="myform" id="myform"action="<?php the_permalink(); ?>" method="post">
<label for="name" class="m">Name: <span>*</span> <br>
<input type="text" class="m" id="name" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>">
</label>
<label for="message_email" class="m">Email: <span>*</span> <br>
<input type="text" class="m" id="email" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>">
</label>    
<label for="message_text" class="m" id="mu">Message: <span>*</span> <br>
<textarea type="text" class="m" id="textm" name="message_text"><?php echo     esc_textarea($_POST['message_text']); ?></textarea>
</label>
<label for="message_human" class="m">Human Verification: <span>*</span> <br>
 <input type="text" class="m" name="message_human"> + 3 = 5
</label>
<input type="hidden" name="submitted" value="1"  class="m">
<input type="hidden" name="submitted" value="1" style="width:100%">
<input type="submit" value="submit" class="subBtn" onclick="formreset();">

 <?php echo $response; ?>
 </form>           
</div>
</div>
  <?php endwhile; // end of the loop. ?>

</div><!-- #content -->

</div>
<?php get_footer(); ?>

0 个答案:

没有答案