Solved

Attempting to submit a form via JavaScript

Posted on 2014-03-21
7
504 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

623 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