Including Forms, Action Problem
Say Im reading a thread or browsing threads
at read.php?tid=1
or category.php?cid=1
respectively
And m开发者_如何学Pythony form post_form.php
which is included();
uses this value for a few isset functions to make sure there is a subject and body, however the form action is pointing to post.php which handles the form, so if no body and subject is submitted, the ?tid or ?cid
is lost and the form brings you to posts.php
What would be the best way to pass the post form the parent tid?
or cid?
value?
You can use type="hidden"
INPUT elements to include values you don't want the user to see/manipulate.
<form ... >
<input type="hidden" name="tid" value="00001"/>
<input type="hidden" name="cid" value="abc-009"/>
...
</form>
Also, if you need to load the CID/TID data into form fields, you can try the following (with hidden fields instead, I used text fields so you could see it working):
CID: <input type="text" id="cid" name="cid" value=""/><br/>
TID: <input type="text" id="tid" name="tid" value=""/>
function getString() {
// You want to use the first one that I commented out, and remove the other.
//var url = unescape(window.document.location);
var url = "http://www.example.com/?tid=0011&cid=mainpromo2";
var get = {};
if (url.indexOf('?') > -1) {
_get = url.substr(url.indexOf('?')+1);
_get = _get.split("&");
for (var i = 0; i < _get.length; i++) {
pairs = _get[i].split('=');
key = pairs[0];
value = pairs[1];
get[key] = value;
}
}
return get;
}
getvars = getString();
document.getElementById('cid').value = getvars.cid;
document.getElementById('tid').value = getvars.tid;
http://jsfiddle.net/userdude/Vuenp/1/
(Note the above needs to run AFTER the form is parsed.)
Of course, this would be easier if you used jQuery.
A hidden HTML element would allow you to send form data between pages.
<form type=""...>
<input type="hidden" name"xx" value="yy" />
</form>
However, be careful relying on the values in hidden form elements, especially if the data is sensitive. Malicious users could alter the form data that gets posted, so you wouldn't want to put something that shouldn't be changed there (like a price).
精彩评论