POST vars from HTML to PHP
I'm not absolutely sure this belongs here, but its what it seems like. I'm having some trouble at my workplace. We're creating a CD from which everything is relative to the CD being able to contain. On one of the html pages of the CD, we want to link the user to our website, which requires username and password. Currently how its done is we link them to the page, but also give them the information they need to log in on an account that has limited access. What we'd like to do is have it skip past the middle step and step right into the sight with limited access.
My thoughts on how to do this was to somehow make the html page POST the limited access username and password to the page. What I can't seem to get around is the need to use a submit button. We want to keep the links as href, so my secondary thought is, could this be done with Javascript? I completely clueless when it comes to javascript and how it works. Everything I've seen that relates to my question doesn't make sense to me as to how they are accomplishing the task.
If someone could please explain how I could POST some variables via html in some form or another, I would greatly appreciate it.
[1225 byte] By [
Culperat] at [2007-11-20 9:54:13]

# 1 Re: POST vars from HTML to PHP
This has nothing to do with JavaScript, just HTML. A submit button simply submits a form.
<form name="loginform" action="http://www.server.com/page.php" method="post">
<input type="hidden" name="variablename1" value="variablevalue1">
<input type="hidden" name="variablename2" value="variablevalue2">
<input type="hidden" name="variablename3" value="variablevalue3">
<input type="submit" value="Submit">
</form>
Now, if you want to submit this form without the user having to click the input button, simply add the following code right below the form. This part is JavaScript.
<script type="text/javascript">
document.loginform.submit();
</script>
# 2 Re: POST vars from HTML to PHP
Having a submit button is what I'm trying to stay away from though. What I'm looking for is to make it a link that will POST variables to the php page when the link is clicked on. Submit button is not the format that is desired for the page.
# 3 Re: POST vars from HTML to PHP
There is no other way to submit a form without a submit button. If you don't want the button, do as I coded just delete the line with the submit button.
You can use AJAX to send post information, but it only returns information so it is not an option in this case.
# 4 Re: POST vars from HTML to PHP
Your method does work, but doesn't allow for differentiated links. Here is what I ended up getting to allow two seperate links.
<form name="loginform1" action="test.php?id=1" method="post">
<input type="hidden" name="username" value="guest" />
<input type="hidden" name="password" value="guest" />
</form>
<form name="loginform2" action="test.php?id=17" method="post">
<input type="hidden" name="username" value="guest" />
<input type="hidden" name="password" value="guest" />
</form>
<a href="javascript:document.loginform1.submit()">publication #1</a>
<a href="javascript:document.loginform2.submit()">publication #17</a>
Thank you for the help. It lead me to the answer I was looking for.