DO NOT DEAL WITH THIS MEMBER
Basically I need to (through javascript) create a post request with a parameter named "submit" (without quotes).
I've previously used a simple html form to generate post requests without any problems but it won't let me do a post request with a parameter named submit - obviously because it collides with the action called submit.
I've been trying to figure out how to do this for a few hours now but with no luck.
Anyone got a bright idea?
Erm, well, can't you just add this to the form?
Code <input type="submit" name="submit"/>
OR in your JS query string:
Code var post = 'post=true';
DO NOT DEAL WITH THIS MEMBER
(Feb 2, 2013 05:10 PM)CarrotMilk Wrote: Erm, well, can't you just add this to the form?
Code <input type="submit" name="submit"/>
That's the problem.
That's what I have now and it messes up as explained in:
http://www.spiration.co.uk/post/1232/Sub...a-function
However the parameter needs to be named "submit"
So what if the parameter needs to be named submit? It's no big deal, lol. There are a TON of ways to get around this. Show code, please.
DO NOT DEAL WITH THIS MEMBER
This is essentially my code (note that I placed in google.com because I can't reveal the real URL).
So essentially I want to post the parameter named submit.
How would I fix this?
Code <script>
function post_to_url(path, params, method) {
method = method || "post";
var form = document.createElement("form");
form.id = 'formid';
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
var paramz = [];
paramz['submit']='Submit';
post_to_url("http://google.com", paramz, "POST");
</script>
I don't see why you're doing that. But then again, it's almost 2am. Why don't you just use a regular HTML form?
DO NOT DEAL WITH THIS MEMBER
(Feb 2, 2013 06:37 PM)CarrotMilk Wrote: I don't see why you're doing that. But then again, it's almost 2am. Why don't you just use a regular HTML form?
It is a html form - it's just being generated by javascript.
The function allows me to make custom post requests at will.
However it really has nothing to do with my original question - how would I post a parameter named "submit" ?
You said there'd be a TON of ways?
(Feb 2, 2013 06:43 PM)Traitor-Panda Wrote: It is a html form - it's just being generated by javascript.
The function allows me to make custom post requests at will.
However it really has nothing to do with my original question - how would I post a parameter named "submit" ?
You said there'd be a TON of ways?
Yes, a ton of ways to get around it. It's just incredibly weird the way you've done it, lol. Just failing to see the point; custom POST requests..? If that's the case, yuno AJAX? Or just HTML hidden fields (like you are doing in the JS)?
DO NOT DEAL WITH THIS MEMBER
Feb 3, 2013 01:51 AM
(This post was last modified: Feb 3, 2013 08:48 AM by Traitor-Panda.)
(Feb 2, 2013 06:44 PM)CarrotMilk Wrote: Yes, a ton of ways to get around it. It's just incredibly weird the way you've done it, lol. Just failing to see the point; custom POST requests..? If that's the case, yuno AJAX? Or just HTML hidden fields (like you are doing in the JS)?
I can't use AJAX since I need to use the users credentials and not the servers credentials.
With javascript the users IP&cookies are being used while with AJAX they're not.
Trust me the only way seems to be the way I'm doing it - I just need to know how to handle the "submit" issue.
EDIT: Got it fixed now.
As CarrotMilk suggested I created a submit button through html and merely invoked a click on the page load.
Works brilliantly.
|