Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Help 

[JavaScript] How to submit a POST param named 'submit' ??

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';
--

:)

--

Best form of contact is email: [email protected]


(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.
--

:)

--

Best form of contact is email: [email protected]


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?
--

:)

--

Best form of contact is email: [email protected]


(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)?
--

:)

--

Best form of contact is email: [email protected]


(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.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Help] by Mr MeeseeksFeb 11, 2016 10:47 AM 3 163 Feb 11, 2016 10:47 AM
Last Post: thedirtybook
[Lua] by PromoyingJan 4, 2015 08:29 AM 5 739 Jan 4, 2015 08:29 AM
Last Post: i n v a l i d
by DungAug 6, 2011 03:40 PM 8 123 Aug 6, 2011 03:40 PM
Last Post: SB91