Naveed Cheema Naveed Cheema - 1 month ago 4
Javascript Question

Reset $_POST values after submition

Basically, I'm trying to do is to reset all the form values after submission. I've tried every post but not got success. Please tell me the way of resetting values after submission so that after refreshing the page the form doesn't submit again. Thank you Here is my piece of code. I've tried headers but it is giving me errors so tell me another way of resetting the submit post after submission.

<form name="myForm" id="myForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" role="form">
<div class="form-group">
<span class="Name_input"> </span>
<input name="Name" id="Name" type="text" class="form-control" required placeholder="Your name" />

<div class="row">
<div class="col-md-6">
<div class="form-group">
<span class="Email_input"> </span>
<input name="Email" id="Email" type="text" class="form-control" required placeholder="Email address" />
<div class="col-md-6">
<div class="form-group">
<input name="Phone" id="Phone" type="text" class="form-control" placeholder="Phone number" />

<div class="form-group">
<span class="Subject_input"> </span>
<input name="Subject" id="Subject" type="text" class="form-control" required placeholder="Subject" />
<div class="form-group">
<textarea class="form-control" name="message" id="message" placeholder="Write you message here..." style="height:100px;"></textarea>
<input type="Submit" name="Submit" value="Send message" class="btn btn-two"/><p><br /></p>

$Inserted=mysqli_query($con, "Insert into feedback (Name , Email, Phone_Number, Subject, Message )
VALUES('" . $User_Name . "', '" .$User_Email . "', '" . $User_PhoneNumber. "', '" . $Feedback_Subject . "','" . $Feedback_Message . "')");


Your form should not resubmit just because you refresh the page. However, I just using header(), to redirect to a fresh page, even if the same.

So, straight after the sql query:

header("Location: page.php");

and replace page with which ever page it is.

also, put

<?php ob_start(); ?>

at the very top (before html) of your script to prevent error: Cannot modify header information - headers already sent