0

I would like to know how I can transfer my selected time/date from one page to another?

My HTML part looks like that:

<form action="http://localhost/HTMLIeskotiAutomobiliu.php" method="post">
<label for="paemimo_laikas">Automobilio paėmimo laikas:</label>
<input type="time" id="paemimo_laikas" name="paemimo_laikas">
</form>

I tried same thing as I did with selected option (<?php echo $_POST['time']?>) but it didn't worked. So I'm looking for yours help.

  • 3
    Have you tried ``? Afterall, `paemimo_laikas` is the name of that input field. – KIKO Software Nov 26 '21 at 12:26
  • Oh yea, thats works, but can I make this value as default like when you open that page you see selected time and if you want you can choose another. – Karolis Kazlauskas Nov 26 '21 at 12:38
  • Learning to search is a super power when you are starting out. Even vague terms like "*php variable another page*" turn up many answers. – Don't Panic Dec 01 '21 at 22:12
  • Does this answer your question? [PHP Pass variable to next page](https://stackoverflow.com/questions/871858/php-pass-variable-to-next-page) – Don't Panic Dec 01 '21 at 22:13

2 Answers2

0

First of all thanks everyone for answers and sorry for disturibing, I just wanted to know how to transfer selected time in the place where you can select time. I found out everything I was needed to do is put php sentence in value.

Something like that:

<input type="time" id="paemimo_laikas" name="paemimo_laikas" value="<?php echo $_POST['paemimo_laikas']?>">
ThS
  • 4,597
  • 2
  • 15
  • 27
-1

If you want to show the current time you can add a js script, like this:

$(function(){     
  var d = new Date(),        
      h = d.getHours(),
      m = d.getMinutes();
  if(h < 10) h = "0" + h; 
  if(m < 10) m = "0" + m; 
  $("#paemimo_laikas").each(function(){ 
    $(this).attr({"value": h + ":" + m});
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="time" id="paemimo_laikas" name="paemimo_laikas">
Luis
  • 31
  • 5
  • 1) OP is clearly taking their first steps with PHP. There is absolutely no reason to involve Javascript. 2) This does not actually answer OP's question. 3) Why iterate with `.each()` over a single element? – Don't Panic Dec 02 '21 at 09:43
  • I read the comments - "*when you open that page you see selected time*". **Not** current time, **selected** time. OP is trying to select a date on one page, and then display that date on the next page. Since this answer does not come close to answering the OP's question, I think that is a clear case for a downvote. – Don't Panic Dec 02 '21 at 21:11