Naresh Yalamanchi
Naresh Yalamanchi

Reputation: 11

How to append dynamic text to url in PHP?

I have a html form which method type is post, now i want to append text to my website url in PHP. The text changes dynamically.

current url :

www.example.com/index.php

expected url :

www.example.com/index.php/hotels-in-bangalore 

(or)

www.example.com/index.php?qry=hotels-in-bangalore

I just want to append text, other than that every thing should remain same. Thank you.

Upvotes: 0

Views: 332

Answers (2)

eL-Prova
eL-Prova

Reputation: 1094

You need to use JavaScript if you want to redirect to correct page after submitting immediately.

So it will be something like this:

<form>
  <input type="text" name="tbSearch" id="tbSearch" />
  <input type="submit" id="submitSearch" value="Submit" />
</form>

<script type="text/javascript">
$("#submitSearch").click(function() {
   window.location.href="index.php?qry=" + encodeURIComponent($("#tbSearch").val());
});
</script>

Upvotes: 0

Mantas
Mantas

Reputation: 232

Im not sure why you try to accomplish, but here are few solutions:

put url in form action:

<form action="index.php?qry=hotels-in-bangalore" method="post">

or you can do it in php

if (!empty($_POST['name']) {//put some logic here
  header("Location: index.php?qry=hotels-in-bangalore");
  exit;
}

Upvotes: 1

Related Questions