-2

Basic question. If I have a form in my HTML (where in my case someone inputs a date), how can I have my users cause a GET request with the contents of that form instead of a POST.

e.g. form entry (e.g date)... so 20190312

what I am trying to achieve is such that AFTER the user submits the form.. the user is the lead to page that has

GET domain.tld/scriptname.php?variable=20190312

and then the system then processes the GET request accordingly.

thank you

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
Matt
  • 133
  • 1
  • 4
  • 13

2 Answers2

2

Maybe i'm missunderstanding what you are asking.
This can easly be achived using builtin GET method in FORM tag


<body>
    <form id="form" method="GET" action="scriptname.php">
        <input id="date-txt" type="text" name="date">
        <input id="search-btn" type="submit" value="Submit">
    </form>
</body>

While filling up above field ad clicking "Submit" form will be submitted and you can see in your url path/or/page/scriptname.php?date=INPUT_FIELD_VAL
for every input in #form with a name, if GET method is used, you'll see a ?name=value in the url

Hele
  • 189
  • 1
  • 12
  • 1
    nailed it.. i had just assumed that all of the forms were handled via POST... learn something every day.. thank you for taking the time to answer a basic question appreciated.. – Matt Mar 12 '19 at 14:36
1

What you describe is the default behaviour of a form. If you don't want a POST request, then don't use a method attribute to set the request type to POST.

<form action="//domain.tld/scriptname.php">
    <input name="variable" value="20190312">
    <button>Submit</button>
</form>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335