Ravi_Ramsagar Posted July 15, 2013 Share Posted July 15, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280162-how-to-reload-a-page-in-php-after-form-submit/ Share on other sites More sharing options...
.josh Posted July 16, 2013 Share Posted July 16, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280162-how-to-reload-a-page-in-php-after-form-submit/#findComment-1440851 Share on other sites More sharing options...
Ravi_Ramsagar Posted July 16, 2013 Author Share Posted July 16, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280162-how-to-reload-a-page-in-php-after-form-submit/#findComment-1440873 Share on other sites More sharing options...
.josh Posted July 16, 2013 Share Posted July 16, 2013 So you're telling me that the form page itself isn't reloaded from the form submit? If that is the case, then in your check_counter() function you can add this: document.getElementById('inv').reset(); Quote Link to comment https://forums.phpfreaks.com/topic/280162-how-to-reload-a-page-in-php-after-form-submit/#findComment-1440926 Share on other sites More sharing options...
Ravi_Ramsagar Posted July 16, 2013 Author Share Posted July 16, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/280162-how-to-reload-a-page-in-php-after-form-submit/#findComment-1440930 Share on other sites More sharing options...
Solution .josh Posted July 16, 2013 Solution Share Posted July 16, 2013 Oh okay I get it.. okay try this: window.open('', 'invoices', 'width=650,height=800,status=yes,resizable=yes,scrollbars=yes'); window.setTimeout("document.getElementById('inv').reset();",100); Quote Link to comment https://forums.phpfreaks.com/topic/280162-how-to-reload-a-page-in-php-after-form-submit/#findComment-1440955 Share on other sites More sharing options...
Ravi_Ramsagar Posted July 17, 2013 Author Share Posted July 17, 2013 Thank you buddy for the help. Quote Link to comment https://forums.phpfreaks.com/topic/280162-how-to-reload-a-page-in-php-after-form-submit/#findComment-1441014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.