Take HTML input value and move to PHP variable

Asked

Viewed 6,946 times

0

I have this input:

    <p>Início do período:</p> <input type="text" id="calendario">

    <script>
    var start = new Date(1997, 12, 01);
    var end = new Date(1998, 11, 31) ;

    $(document).ready(function() {
        $('#calendario').datepicker({
           startDate: start,
           endDate: end
        });
    });
</script>

I need the value the user will select, how could I put this value in a php variable?

  • Now it’s better ;)

  • That’s exactly what I wanted as an answer, an edited that put the code of the properties, but answering you here, I’ll take the value of the date to put in a select.

  • could exemplify here for me @Raizant?

1 answer

0


<input type="text" id="calendario" name="calendario">

Add a name to your field in php you can get via $_POST or $_GET depends on the method you send to the serivodor

<?php
if(isset($_POST['calendario'])){
    $calendario = $_POST['calendario'];
}
?>

Your form should look like this

<form method="post" action="urlp do seu site">
    <input type="text" id="calendario" name="calendario">
    <input type="submit" value="enviar">
</form>
  • didn’t quite understand this part of the form, it would be how I would display the calendar to the user and take the value in html?

  • I tested your code here... In fact what I will want is for the user to enter the start date and the end date, because my select has will be relative to a period, so Submit will have to take the value of 2 inputs, I should add another calendar there then it would be : <form method="post" url="urlp of your site"> <input type="text" id="calendario1" name="calendario1"> <input type="text" id="calendario2" name="calendario2"> <type input="Submit" value="send"> </form> thus, @Marcos Brinner pikatoons ?

  • This is to take the start and end value from html to the correct php ? so is this msm vc just need to create one more html field igua vc mentioned above

  • one last question, I could make Submit out of the form tag?

  • yes, but you’ll have to use it $("#formID"). Submit() search for the jquery/javascript Submit function

  • I tested the code with the 2nd input here and it didn’t work, the calendar with the properties of datepicker... another question: the url would receive the path from the root to the folder where the page is?

  • vc will have to call the datapicker again to the other $("#calendario2") field. datepicker(); in its javascript

  • You will receive the data on the same page ? if it is not set define action="" if it is for another page define action="//seustie.com/page/path.php"

  • is not url I had put wrong is action

  • is all on the same page, for you to understand better, the problem is this: I have to pick the start date and end date to determine a period and make a select, after the user select the dates I will display a table with which my select return. All this on the same page.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.