Jump to content

How to reload a page in php after form submit


Ravi_Ramsagar
Go to solution Solved by .josh,

Recommended Posts

An invoice will be opened in a new window when the Generate invoice button is clicked.

Below is the sample code. For Example

<form name="invoice" action="inv_rec.php" method="post" id="inv" target="invoices" onsubmit="return check_counter();" >
    <table>
    <tr>
       <td>
          <label for="cusname"><strong>Customer Name* </strong></label>
          <input type="text" size="20" name ="cusname" value="" id="Customername"     required/>
       </td>
       <td>
           <label for="for_place"><strong>Place</strong></label>
           <input type="text" size="20" name ="for_place" value=""  id="for_place" />
       </td>
    </tr>
    ........
    <tr>
        <td>
            <input type="submit" value="Generate Invoice" name="submit" id="sub">
        </td>
     </tr>
  </table> 
</form>
<script>
var counter = 1;
function check_counter()
{
 if(counter == 1)
{
 alert("Please enter the product details");
 return false;
}
 window.open('', 'invoices', 'width=650,height=800,status=yes,resizable=yes,scrollbars=yes');

return true;
}
</script>

In my example the page will be redirected to inv_rec.php(opens in new window) which contains dynamically generated data obtained from mysql where the user needs to take the print of it. I want to clear all the form data which is open in the previous window(where the invoice form is displayed,i.e user fills the data to generate a invoice).Any help is appreciated.

Link to comment
Share on other sites

without seeing your full code my guess is that your server-side script is dynamically populating the form fields, probably something along the lines of this in principle (in reality your php code would probably be using a condition to check if $_POST['cusname'] is set first):

<input type="text" size="20" name ="cusname" value="<?php echo $_POST['cusname']; ?>" id="Customername" required/>

so basically you will want to remove that server-side code. If I had to keep on guessing, I'd say your server-side code probably does that so that if form validation fails, the visitor doesn't have to re-fill out the entire form.  And that "fill in the blanks" code probably isn't put inside that form validation.   So ideally maybe you should look to move that code or else tie it to the form validation code so that you don't break that functionality.  

 

But this is all just guessing, since I don't know what your server-side code looks like.

Link to comment
Share on other sites

No the server-side script does not populate any dynamic data in the form by name "invoice". The form by name "invoice" is just used to fill the data that is required to generate an invoice.When all the data in the form by name"invoice" is filled and clicked on a "Generate Invoice" button, an invoice(opened in new window) will be generated with data fetched from the db will be displayed in it.Meanwhile the data I filled in the form by name "invoice" will be still open in the browser tab so that by clicking again on the  "Generate Invoice" button will again generate an invoice with same details in a new window. I want to clear the form by name  "invoice"  so that the same invoice is not reprinted again.

Link to comment
Share on other sites

Thanks for the response.Yes the form itself is not reloaded from the form submit.

 

I tried with document.getElementById('inv').reset(); in the check_counter function but no luck. Actually the form gets reloaded but an empty invoice with no details will be opened in new window as the form gets reloaded on form submit.I want to submit the form that is an complete invoice has to be generated then the form should get reloaded. 

<script>
var counter = 1;
function check_counter()
{
 if(counter == 1)
{
 alert("Please enter the product details");
 return false;
}
document.getElementById('inv').reset();
 window.open('', 'invoices', 'width=650,height=800,status=yes,resizable=yes,scrollbars=yes');

return true;
}
</script>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.