How To Blank The Page Before Submitting PHP Form To Same Page? -


i'm trying create auto-response script work display form fields required, such name, username, , password. once select submit, want script remove form, , display output corresponding response in stead without having post page. having form.php , result.php each individual scenario want cluttered, hence why i'm trying accomplish this. far form, have:

<form action="<?php echo htmlentities($_server['php_self']); ?>" method="post">     <table width="100%" cellpadding="10" cellspacing="0">         <tr>             <td style="width:33%">              </td>             <td style="width:33%">&nbsp;</td>             <td style="width:33%">&nbsp;</td>         </tr>         <tr>             <td colspan="3" style="width:99%">                 <label>name</label><span class="req">*</span>                 <span id="reqname" style="color:red;display:none;">&nbsp;</span>                 <br />                 <input type="text" name="name">             </td>         </tr>         <tr>             <td colspan="3" style="width:99%">                 <label>username</label><span class="req">*</span>                 <span id="reqproblem" style="color:red;display:none;">&nbsp;</span>                 <br />                 <input type="text" name="username">             </td>         </tr>         <tr>             <td colspan="3" style="width:99%">                 <label for="txtproblem">password</label><span class="req">*</span>                 <span id="reqproblem" style="color:red;display:none;">&nbsp;</span>                 <br />                 <input type="text" name="password">             </td>         </tr>         <tr>             <td colspan="3" style="width:99%">             <br />             <input type="submit" name="submit" value="submit">             </td>         </tr>     </table> </form> 

for php have:

<?php if(isset($_post['submit'])) {     echo "<h4>response</h4>";     $username = $_post['username'];     $password = $_post['password'];     $name = $_post['name'];      echo "<p>hello, $name <br />       login information follows:     username: $username     password: $password. </p>"; } ?> 

so sum up, want remove before php isset , replace corresponding result.

in present form happens html sent off browser (or @ least invisible buffer on way browser) , out of control once you've gotten part of script controls form processing.

so you've got 2 choices. 1 leave in state have use output buffering ob_start() , related functions - don't recommend in case - or re-arrange order of code.

in general common design pattern these one-page self-processing forms have processing logic @ top, , output of form or success/failure message conditional on results.

to implement take php code , move top of file. @ end of present post code, if post successful output message nothing else. if isn't successful, or if there has not yet been post, output form html. along these lines:

<?php if($no_post_or_failure) { // output html ?> <form action="<?php echo htmlentities($_server['php_self']); ?>" method="post"> ... <?php } // aaaand we're done! ?> 

and that's it. hope made sense :)


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -