开发者

PHP form post- submitted message

开发者 https://www.devze.com 2023-02-21 18:17 出处:网络
I am using a PHP scrip开发者_如何学JAVAt to submit an email to the database, after the user submit, I am doing a small validation and submit it.

I am using a PHP scrip开发者_如何学JAVAt to submit an email to the database,

after the user submit, I am doing a small validation and submit it.

everything is working just fine, but instead of postback the user to the same page with a blank textbox, I want to add a label says "Submitted successfully". I managed to do so, but the problem is when I just refresh the page- without really pressing the "submit" button, I still get to see the message- submitted successfully... this is a small part of my code:

<form action="<?php echo $editFormAction;?>" method="post" name="form1" id="form1">
      <table align="center">
        <tr valign="baseline">
          <td nowrap align="right">Email:</td>
          <td><span id="sprytextfield1">
          <input type="text" name="Email" id="Email" value="" size="32">
          <input type="submit" value="Submit"><br/>
          <div id="confirm">
          <?php
            if(isset($_POST['Email']))
                echo "<font color='green' size='5'><b>Submited Successfuly!</b></font><br/>";
          ?>
          </div>
          <span class="textfieldRequiredMsg"><font size="+2"><b>Insert an Email Address</b></font></span>
          <span class="textfieldInvalidFormatMsg"><font size="+2"><b>Invalid Email Address!</b></font></span>
          </span>
          </td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
  </form>


There are 2 ways to do it.

  1. Send your form using AJAX. A page wouldn't be reloaded upon submit.

  2. Use sessions to store this message, then reload page using Location: header, then display message and delete it from session.


Try

if(!empty($_POST['Email'])) {
     //successful submit
}

empty will check if the value is an empty string.


You need to unset your post variable after message diaplay

Submited Successfuly!
"; unset($_POST['email']; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消