Results 1 to 11 of 11
-
12-31-2005, 11:36 AM #1Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
[HTML] submit form on page load (Not working)
Hello,
I was experimenting with javascript and forms to see if i can submit values to a php file on form load. This is what i made so far:
PHP Code:<html>
<head>
<title>Test</title>
<script language="javascript">
function MyFormSubmit(){
document.form.submit
}
</script>
</head>
<body onload="MyFormSubmit()">
<FORM ACTION="http://localhost/test.php" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="username" VALUE="latheesan">FORM>
</body>
</html>
how comes this inst working?:: www.AsuraHosting.com ::
-
12-31-2005, 12:05 PM #2Web Hosting Master
- Join Date
- Feb 2002
- Location
- New York
- Posts
- 791
is some of that code missing where is the submit button? Have you thought of just using pure php so you have a html form and then you do a
if ($HTTP_POST_VARS['submit']) {
type tag
what are you trying to do with the form contents?
-
12-31-2005, 01:37 PM #3Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
i know this method:
if ($HTTP_POST_VARS['submit']) {
but what i wanted to know is a method of auto-submit hidden values that is found on the html form to a php file, when the html file loads.:: www.AsuraHosting.com ::
-
12-31-2005, 02:15 PM #4Web Hosting Master
- Join Date
- Mar 2004
- Location
- USA
- Posts
- 4,345
Two things,
HTML mistakes
You will go into an infinite loop (will just keep submitting):
PHP Code:<html>
<head>
<title>Test</title>
<?php
if($_POST['username'] == NULL){?>
<script language="javascript">
function MyFormSubmit(){
document.myname.submit();
}
</script>
<?php } ?>
</head>
<body onload="MyFormSubmit()">
<FORM ACTION="http://localhost/test.php" METHOD="POST" name="myname" id="myname">
<INPUT TYPE="HIDDEN" NAME="username" id="username" VALUE="latheesan"> </FORM>
</body>
</html>Testing 1.. Testing 1..2.. Testing 1..2..3...
-
12-31-2005, 03:33 PM #5Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
Nicely done azizny. It worked.
Thanks for ur help.
Peace,:: www.AsuraHosting.com ::
-
12-31-2005, 03:37 PM #6Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
One last question.
What if i have a list of usernames in array();
how can i integrate foreach() loop to do this form submission ?:: www.AsuraHosting.com ::
-
12-31-2005, 04:33 PM #7Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
I've tried it like this:
PHP Code:<?php
$list["david"] = "221";
$list["smith"] = "179";
$list["cleos"] = "879";
$i = 0;
while ($i < 1)
{
foreach($list as $user => $id)
{
if(($_POST['user'] == NULL) && ($_POST['id'] == NULL))
{
echo "<script language=\"javascript\">
function MyFormSubmit()
{
document.top.submit();
}
</script>";
}
echo "<body onload=\"MyFormSubmit()\">
<form action=\"test.php\" method=\"POST\" name=\"top\" id=\"top\">
<input type=\"hidden\" name=\"user\" id=\"user\" value=\"$user\">
<input type=\"hidden\" name=\"id\" id=\"id\" value=\"$id\">
</form>
</body>";
}
$i++;
}
?>
can someone help me work out why it isnt working plz?:: www.AsuraHosting.com ::
-
12-31-2005, 04:35 PM #8Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
why do i need $_POST['user'] == NULL this again?
:: www.AsuraHosting.com ::
-
12-31-2005, 04:37 PM #9Web Hosting Master
- Join Date
- Jan 2005
- Location
- UK, London
- Posts
- 764
should i have the foreach loop first and then bring in the while loop? how is this done
:: www.AsuraHosting.com ::
-
12-31-2005, 09:34 PM #10Web Hosting Master
- Join Date
- Mar 2004
- Location
- USA
- Posts
- 4,345
I have to understand what you want to do?
You cant have more than 1 body tags on the same page, well at least you shouldnt?
Peace,Testing 1.. Testing 1..2.. Testing 1..2..3...
-
01-01-2006, 09:50 AM #11Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
You don't need the while(), and your loop will never print the form along with the javascript. Just look at the source of your script (view source in the browser).