Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass the form data and redirect to another page [closed]

I am creating a website that has a form of following details:

  1. Country code
  2. mobile number
  3. message
  4. submit button

If any users fill the form and submit, I would like to pass that data to www.example.com/subfolder/example.php but after submission of data example.php redirects me in www.example.com/index.html.

So my question is: can I make a form so that the user could be redirected to the specific location that I want instead of to the current redirect to www.example.com/index.html

This is my form code, it is located at http://www.datafilehost.com/d/b68c527d

<form name="forma" method="post" id="myForm" action="www.example.com/subfolder/example.php">
  <input type="text" value="+977" id="Countrycodepre" name="Countrycodepre" readonly="readonly">
  <textarea wrap="off" autocomplete="off" cols="10" rows="1" type="text" name="country_mobile_number">
  <button name="submit" class="button100" id="submit" type="submit">Submit</button>
</form>
like image 670
sulochan Avatar asked Nov 28 '25 18:11

sulochan


2 Answers

You cant do this using a standard HTML form. The PHP page will redirect the browser to the new page and if you cant change the PHP, you cant affect the redirect.

Instead, you can post your form via AJAX. If you do this, your browser will not automatically follow the redirect. Then you can use JavaScript to redirect the page anywhere you want. If you go this way, you may be interested in using jQuery and the jQuery Form Plugin.

like image 94
Jeff Avatar answered Nov 30 '25 08:11

Jeff


Add this:

header("Location: yourLocation.php");

to example.php.

like image 21
Jeroen Avatar answered Nov 30 '25 09:11

Jeroen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!