user3596343
user3596343

Reputation: 1

How to prevent information on a page from resetting after a submit button is clicked (PHP)

So I have 1 file(HTML) that allows a user to select appointment times for the day(s) of the week. After clicking submit, the 2nd file(PHP) builds a calendar and displays the chosen times on the chosen days (as checkboxes). On this page, I'd like to have the user enter a name, while picking which time(s) they'd like to make an appointment -- then have their name appear next to the times they just chose. However, when I enter the name and click submit or just click submit, the times go away and an empty calendar appears.. any ideas?!

-I used a POST form inside my html file (for choosing initial times) with the action = my php file.

-I used a POST form inside my php file (for typing in name) with the action = itself

Upvotes: 0

Views: 640

Answers (3)

thewheat
thewheat

Reputation: 988

I believe you have to handle this yourself using code similar to below

<?php
$test = (isset($_POST['test']) ? $_POST['test'] : "");
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="test" value='<?php echo $test; ?>'>
<input type="submit">
</form>

Upvotes: 1

de coder
de coder

Reputation: 1

Once you get the posts from the first HTML file in the 2nd file, see that you put these post values as hidden variables (with same names as in the HTML file) in the 2nd files form. It should work.

Explanation: From what I see your post from the first HTML is helping to fill up the calender, but when you submit the form on the 2nd page these values are not there for the calender to fill up. So you need to see that these values are posted by your second form as well.

Upvotes: 0

rhbvkleef
rhbvkleef

Reputation: 213

Every time the page gets reloaded check if there is any POST data available. If so, put it into the input field using 'value='

Upvotes: 0

Related Questions