hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : [HTML] submit form on page load (Not working)
Reply

Forum Jump

[HTML] submit form on page load (Not working)

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
AsuraHosting.Com
 
Join Date: Jan 2005
Location: UK, London
Posts: 762

[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> 
when i load opened the this page (test.html), it was suppose to post the value "latheesan" to the php script "test.php" file. But it didnt. If it did successfully posted that value, my php file wud say, "you name is latheesan"

how comes this inst working?

__________________
:: www.AsuraHosting.com ::



Sponsored Links
  #2  
Old
Web Hosting Master
 
Join Date: Feb 2002
Location: New York
Posts: 786
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?

  #3  
Old
AsuraHosting.Com
 
Join Date: Jan 2005
Location: UK, London
Posts: 762
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 ::

Sponsored Links
  #4  
Old
Web Hosting Master
 
Join Date: Mar 2004
Location: USA
Posts: 4,342
Arrow

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>
Peace,

__________________
Testing 1.. Testing 1..2.. Testing 1..2..3...

  #5  
Old
AsuraHosting.Com
 
Join Date: Jan 2005
Location: UK, London
Posts: 762
Nicely done azizny. It worked.

Thanks for ur help.

Peace,

__________________
:: www.AsuraHosting.com ::

  #6  
Old
AsuraHosting.Com
 
Join Date: Jan 2005
Location: UK, London
Posts: 762
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 ::

  #7  
Old
AsuraHosting.Com
 
Join Date: Jan 2005
Location: UK, London
Posts: 762
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++;
}
?>
unfortunetly it isnt working

can someone help me work out why it isnt working plz?

__________________
:: www.AsuraHosting.com ::

  #8  
Old
AsuraHosting.Com
 
Join Date: Jan 2005
Location: UK, London
Posts: 762
why do i need $_POST['user'] == NULL this again?

__________________
:: www.AsuraHosting.com ::

  #9  
Old
AsuraHosting.Com
 
Join Date: Jan 2005
Location: UK, London
Posts: 762
should i have the foreach loop first and then bring in the while loop? how is this done

__________________
:: www.AsuraHosting.com ::

  #10  
Old
Web Hosting Master
 
Join Date: Mar 2004
Location: USA
Posts: 4,342
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...

  #11  
Old
Community Guide
 
Join Date: Jul 2003
Location: Kuwait
Posts: 5,099
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).

__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise

Reply

Related posts from TheWhir.com
Title Type Date Posted
RightSignature Acquisition Gives Customers Digital Signature Option with Citrix ShareFile Web Hosting News 2014-10-21 08:33:08
New Plugin Provides Communication Between VMware vCenter Orchestrator and Array Networks’ ADC Products Web Hosting News 2014-10-15 17:37:19
Rackspace Launches Automatic Cloud Scaling Capabilities Web Hosting News 2013-11-21 12:07:13
The Impact of Third-Party Ad Networks on Site Load Times Web Hosting News 2014-05-09 12:40:28
Netflix Outage Caused by EC2 Downtime: Reports Web Hosting News 2012-12-24 21:05:12


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?