Reputation: 10094
Im trying to use the query string to pass data from page to page, i understnad how to pass the fixed data, ie if you clicked a button that would send you to page A and add a fixed query to the string.
But im unsure about how to get data from an input and place that in the query string.
Ive tried several approaches but couldnt get any of them to work any idea how i would do this ?
form action="index.php" method="post" id="myform">
<input type="text" name="text" id="link" placeholder="Paste" />
<?php printf("<a class='btn btn-large btn-block btn-primary insert' href=\"about.php?url=%s\">%s</a>", $url, 'Insert'); ?>
</form>
Upvotes: 0
Views: 1591
Reputation: 498
You could try something like this
HTML
<form action="doWhatever.php" method="post" id="myForm">
<input type="text" name="text" id="text" placeholder="Put your text here" />
<input type="submit" name="submit" id="submit" value="enter" />
</form>
PHP (doWhatever.php)
<?php
$input = $_POST["text"];
header("Location: goWherever.php?" . http_build_query(array('text' -> $input)));
?>
I am assuming you want to load in a special way based on want the user inputs. And if that is the case might I suggest you use session
variables instead of GET
variables
Like this...
PHP (doWhatever.php)
<?php
session_start();
$_SESSION["input"] = $_POST["text"];
header("Location: goWherever.php");
?>
HTML (goWherever.php)
<?php
session_start();
if($_SESSION["input"] == 'foobar'){
//load the page one way
}
else{
//load the page some other way
}
?>
Upvotes: 1