Solved

Attempting to submit a form via JavaScript

Posted on 2014-03-21
7
490 Views
Last Modified: 2014-03-21
Hello,

I am attempting to send a form by using the syntax document.getElementById("ID").submit();

Here is my code:

<?php
echo "<form action='../login.php?pass=yes' id='passForm'>
		<input type='hidden' id='usr' value='". $_POST["usr"]. "' />
		<input type='submit' />
	</form>";
?>
<script language="javascript" type="text/javascript">
                document.getElementById("passForm").submit();
</script>

Open in new window


The $_POST["usr"] is from the form that went to this page.  The submit() is only submitting login.php?.  In other words, even the action string is '../login.php?pass=yes, submit is only using '../login.php?.

if I do alert(document.getElementById("passForm").action), the complete string is displayed.

Any help is greatly appreciated.

Have a great day,

Don
0
Comment
Question by:GEMCC
  • 4
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39946680
Code works fine but pass=yes will not be passed, it will be replaced with any inputs in the form
0
 

Author Comment

by:GEMCC
ID: 39946717
So how do I get the complete URL to submit?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39946720
Change the FORM METHOD to POST

echo "<form action='../login.php?pass=yes' method='POST' id='passForm'>

Then you can get the url params with $_GET and the FORM values with $_POST
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Closing Comment

by:GEMCC
ID: 39946726
Thanks!  Now it works!  I forgot about method="post"!
0
 

Author Comment

by:GEMCC
ID: 39946739
I kinda jumped too soon to mark the answer as accepted.  I am now getting to the proper URL, but <input type='hidden' id='usr' value='". $_POST["usr"]. "' /> is not being posted.  In other words, the value does not go to ../login.php?pass=yes.

Now what am I doing wrong/ missing?

Thanks for your help!
0
 
LVL 58

Expert Comment

by:Gary
ID: 39946746
Your input needs a name otherwise it won't be POSTed
0
 

Author Comment

by:GEMCC
ID: 39946749
Again, a brain fart, I was thinking about CSS (id).

Thanks again
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now