0

So basically, I have a form with a post method. When I click submit, I can work with the POST superglobal values in PHP, but it clears all the textbox and radio button values and that's what I want to prevent. (I don't think my code is important, just a basic form, nothing special). Tried adding onsubmit="return false" in my HTML form tag, but then my submit button did nothing. I tried these, none of them worked: How to stop form auto-reset in JS and HTML? How to stop the form from resetting

So, how can I prevent the form from clearing all the data but do the POST method?

  • You either need to use Ajax to send the form data to a PHP script, or use the `value` attribute on the form elements to re-insert the value when the page is reloaded by the form (e.g `value="= $_POST['input_name'] ?>"`). – GrumpyCrouton Jan 24 '20 at 17:49
  • you can print the values again with PHP, or save the values in browser session storage – Akam Jan 24 '20 at 17:50
  • A form submit works just like any other page request / link, in that the current web page is a replaced with a new one. Unless the new form fields are prefilled by your PHP script, they'll show up empty as declared. – mario Jan 24 '20 at 17:50
  • you need in this case to submit from ajax request – Joseph Jan 24 '20 at 17:52
  • Or, if you don't want to do it with PHP, prevent the default and use [`serialize`](https://api.jquery.com/serialize/) and [`$.ajax`](https://api.jquery.com/jQuery.ajax/); – T.J. Crowder Jan 24 '20 at 17:53

0 Answers0