I am making a form using $_GET, I am wondering how to omit some variables from the URL. For example, after you hit next, the URL is: test.php?guidline=web&btnNext=Next. Can I make it test.php?guideline=web only?
<?php
// if the form has been submitted, create the query string and redirect
if (isset($_POST['btnNext'])) {
// change the url to your page
$url = 'http://www.yoursite.com/pagename.php?guideline=' . $_POST['guideline'];
header("Location: $url");
exit();
}
// if the page has been redirected (the querystring contains 'guideline') show the appropriate message, if not show the form
if (!isset($_GET['guideline'])) {
// Use the POST method so the button doesn't appear in the query string before the redirect
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="s508">
<label for="guideline">What do you need?</label>
<select id="guideline" name="guideline">
<option value="doc">Creation of a document</option>
<option value="web">Creation of a website</option>
<option value="other">Other</option>
</select>
<input type="submit" value="Next" name="btnNext" id="btnNext">
</form>
<?php
} else {
switch ($_GET['guideline']) {
case "doc":
echo 'You will be creating a document';
break;
case "web":
echo 'you will be creating a website';
break;
case "other":
echo 'your project will be difficult, call me';
break;
}
}
?>
No need for many files. Let the form call its own script, like you are already doing, and if the form is submitted, redirect to the same script again with a query string
Verifying user input isn’t needed since it is just drop downs. I thought about directing to ./web.php etc but he “doesn’t want that many files.” 3-5 files on a tb drive isn’t that much IMHO, to each his own I guess.
So nothing could be done, and the server was being nice last night?
Any reason why you couldn’t use POST if you don’t want data to appear in the query string?
My boss wants the ability to have users bookmark the results ?guidelines=web (internal form, most users will always use the same results), and he doesn’t think ?guidelines=web&btnNxt=Next looks pretty
If you don’t give the button a name, $_GET[‘btnNext’] is never set.
Any reason why you couldn’t use POST if you don’t want data to appear in the query string?
I may be missing something here, but can’t the OP just leave out the name of the submit button and check for $_GET[‘guideline’] instead of $_GET[‘btnNext’] ?
I don’t see why that wouldn’t work …
It’s not like there are multiple submit buttons and they need to know which one was clicked, so a name isn’t necessary for the submit button …
I got my form almost done last night, when I came in today it wasn’t. Can fresh eyes look/
<?php
if(!isset($_GET['btnNext'])){ ?>
<form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="s508">
<label for="guieline">What do you need?</label>
<select id="guideline" name="guideline">
<option value="doc">Creation of a document</option>
<option value="web">Creation of a website</option>
<option value="other">Other</option>
</select>
<input type="submit" value="Next" id="btnNext">
</form>
<?php } else {
switch($_GET['guideline']){
case "doc":
echo 'You will be creating a document';break;
case "web":
echo 'you will be creating a website';break;
case "other":
echo 'your project will be difficult, call me';break;
}
}
?>
So what this should do is pop the correct in the right statement where the form is. Obviously I simplified the form here, but even puttiing this simple form up doesn’t work.