Fleksiu
Fleksiu

Reputation: 191

PHP post - converting time in form

i want to build a site, where a user can choose a timeslot. This timeslot should be printed on the following site. But i have a problem with the correct presentation or displaying the chosen time.

Here my code so far:

Site1, where the user choose a timeslot:

                    <form name="Uhrzeit" action="confirmation.php" method="POST">
                <?php
                $start = 10;
                $end = 18;

                for ($time = $start; $time <= $end; $time++) {
                    echo "<input type='radio' name='Zeit'>";
                    echo date("H:00", mktime($time+0,25)).'<br>';
                  }
                ?>
                <input type="submit" value="Wählen">
                </form>

Site2, where the chosen time should be printed:

<?php
$new_date = date('H:00', strtotime($_POST['Zeit']));
echo $new_date;
?>

But with this i get everytime the output of "01:00".

Upvotes: 0

Views: 47

Answers (1)

Hirak Sheth
Hirak Sheth

Reputation: 359

Please try below code

<form name="Uhrzeit" action="confirmation.php" method="POST">
<?php
$start = 10;
$end = 18;

for ($time = $start; $time <= $end; $time++) {
echo "<input type='radio' name='Zeit' value='".date("H:00", mktime($time+0,25))."'>";
echo date("H:00", mktime($time+0,25)).'<br>';
}
?>
<input type="submit" value="Wählen">
</form>

Upvotes: 1

Related Questions