i am looking for a simple quick solution to fill URL fields from a basic HTML menu (user choice) using PHP.
for example: www.123.com/test.php?choice_1=USER_Input**t&choice_2=**USER_Input
so im looking to fill these 2 bold fields with the user choice and then request it. Its something i was asked to do at work and i don't have the privileges to access the database. I can only request a web page.
urlencode
the data.
$url = "http://example.com/test.php?choice_1=" . urlencode($input1) . "&choice_2=" . urlencode($input2)
Quick guide:
<form action="index.php" method="get">
<input type="text" name="input1" id="input1"/>
<input type="text" name="input2" id="input2"/>
<input type="submit" value="Submit">
</form>
URL will look something like this: index.php?input1=VALUE&input2=VALUE
.
Describe this HTML menu, is it a javascript one or a plain HTML menu with links in it? A javascript menu is more flexible and will let you pick multiple choices. Personally I would just use a HTML form and post it. Then you can do
header('Location: http://www.example.com/test.php?choice1=' . $POST['one'] . '&choice2=' . $POST['two']);
$url = 'http://123.com/test.php?';
$parts = array();
$request = array(
'input_1' => $_POST['input_1'],
'input_2' => $_POST['input_2'],
'input_3' => $_POST['input_3'],
);
foreach ($request as $key => $value) {
$parts[] = "{$key}={$value}";
}
$url .= implode('&', $parts);