QUERYSTRING not displaying in URL nor setting in PHP from JavaScript [RESOLVED]
I've been using the following code successfully to display two buttons that would browse to either the Manager page or to the History page.
<FORM METHOD="GET" ENCTYPE="application/x-www-form-urlencoded">
<button type="submit" onClick='JavaScript: form.action="admin/index.php";'>Manager Page</button>
<button type="submit" onClick='JavaScript: form.action="history/index.php";'>History Page</button>
</FORM>
Now I'd like to pass a QUERYSTRING when the Manager button is pressed, "dir=a", but it does not display in the browser URL Address box and certainly is not present in $_GET['dir'] from PHP.
<FORM METHOD="GET" ENCTYPE="application/x-www-form-urlencoded">
<button type="submit" onClick='JavaScript: form.action="admin/index.php?dir=a";'>Manager Page</button>
<button type="submit" onClick='JavaScript: form.action="history/index.php";'>History Page</button>
</FORM>
I even tried changing onClick to onSubmit with no success.
<FORM METHOD="GET" ENCTYPE="application/x-www-form-urlencoded">
<button type="submit" onSubmit='JavaScript: form.action="admin/index.php?dir=a";'>Manager Page</button>
<button type="submit" onClick='JavaScript: form.action="history/index.php";'>History Page</button>
</FORM>
Now I just noticed that the ? is appearing (so I assume it was always appearing) in my browser URL Address box appended to index.php like so index.php?, even though I had no querystring. JavaScript is turned on in my browser.
What am I missing? And why would I intermittently see a session id in the URL Address box? I'm not turning cookies on and off.
I might try passing another session variable around instead of the querystring, but I don't see why I should have to.
I'd say this has become a "Best Practices" discussion
The Hobo's technique solved my problem, but we can continue this for best practices.
Quote:
why go out of your way to use javascript when you don't have to.
JavaScript is in there because I was using it anyway for form validation, and I had seen it as a solution for using multiple buttons to submit a form. So I was building on JavaScript and having multiple FORMS per each single button seemed incorrect. For the two button part that I posted about, I agree as far as best practices, that it would make sense to just use html and the multiple forms.
I never would have thought to use POST since I wasn't sending anything large or private.
Quote:
if you are worried about javascript being off them why do it that way?
My PC had been acting funny (things solved? by rebooting), so I thought it may have turned off JavaScript without my knowing it.
Quote:
also why do you have the enctype in there?
I think this is the default ENCTYPE, but I just put it in explicitly.
Quote:
you can have it set int the php.ini to put the session_id in the url automatically, or you can do it in the htaccess file. depending on your host.
I mentioned that I was using PHP Sessions because I thought it might help diagnose the problem.
Quote:
in order to send variables to anotehr page VIA a GET from a form you first have to put the varialbe in the forms action. making the variable in a hidden form input will not send it in the url. if you want hidden form inputs you have to use POST
I haven't tried your code. But wouldn't it disagree with CornedBee's comments about the browser stripping away custom querystrings? I actually didn't need to hide the data, I just needed to pass it.
Thanks for your opinion.
It's nice to have options (or know the best practices)
CornedBee,
So then what I could have done was to use the code I had in my original post of this thread but change from the GET method to the POST method (and I still would have received $_GET['dir']=a)?
Code:
<FORM METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">
<button type="submit" onClick='java script: form.action="admin/index.php?dir=a";'>Manager Page</button>
<button type="submit" onClick='java script: form.action="history/index.php";'>History Page</button>
</FORM>