12, October 2008

PHP forms - a few questions - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: PHP forms - a few questions
« previous next »
Pages: [1] 2 Print

Author Topic: PHP forms - a few questions  (Read 1112 times)
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« on: Feb 09, 2007, 07:58:49 PM »

Hi all, I am working on building a PHP form on my website.  It is a long form and I need it to email to me using PhP.    I would also like to format it nice in the email I will receive.  My form has, text areas, radio buttons, check boxes, etc. 

I am looking for a good tutorial (free) or someone to give me some pointer. 

Any help would be appreciated.

Thanks
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #1 on: Feb 09, 2007, 08:45:13 PM »

Code:
<?php
mail
($emailaddress,$subject,$message)
will send the e-mail. You can format the message any way you want and store it in the $message variable:
Code:
<?php
$message 
"
A form has just been submitted by $name from $location.

His favorite color is: $color and his lucky number is $luckynum.

Have a nice day!"
;
where the variables used in the message are the variables used in the form. Hope this helps!
« Last Edit: Feb 09, 2007, 08:48:53 PM by Mind_nl »


Last blog : Are You Stumbling Yet?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6349
38918 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Feb 10, 2007, 12:39:37 PM »

note there are some special things with checkboxes (unchecked = not exists)

check this example:
http://www.finalwebsites.com/snippets.php?id=3 Visit through proxy


Last blog : Upload images for usage in TinyMCE
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #3 on: Feb 10, 2007, 04:48:21 PM »

OK, but I wan to UNDERSTAND how it works, any suggestions there.

BTW, bare with me I have the flu so I am not thinking as clearly as usually.
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #4 on: Feb 10, 2007, 07:05:16 PM »

This is how it goes.

A form can be POST or GET. eg.

Code:
<form method="get">

Any item of this form has a name which will later be used from php to access that information. eg.

Code:
<input type="text" name="XXX">

In the above example when someone submit that form, the script that process it will be able to use this form this way :

<?phpecho $_GET['XXX'];

If the form was method="post" then that would be :

<?phpecho $_POST['XXX'];

Any questions on this example? Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #5 on: Feb 13, 2007, 05:49:33 PM »

Can you give me a more detailed example?  I am still confused.  I feel like I am just missing something.  I'm still sick, so maybe that's it.  But I feel silly b/c I know that the information I am looking for is just right there on the tip of my consciousness. 
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #6 on: Feb 13, 2007, 06:00:44 PM »

Create a php file and write this :

Code:
<?php
echo '<form method="get" action="' $_SERVER['PHP_SELF'] . '">
<input type="text" name="variable1"></input>
<input type="text" name="variable2"></input>
<input type="submit"></input>
</form>
'
;
if ( !empty(
$_GET['variable1']) ){
 echo 
'<pre>This is the $_GET array as it posted through the form :<br />';
 
var_dump($_GET);
 echo 
'</pre>';
}
?>


Add something to the form fields and submit it.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #7 on: Feb 13, 2007, 06:06:55 PM »

OK, now how do I get it to mail to me?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #8 on: Feb 13, 2007, 06:13:15 PM »

ok do this :

Code:
<?php
echo '<form method="get" action="' $_SERVER['PHP_SELF'] . '">
<input type="text" name="variable1"></input>
<input type="text" name="variable2"></input>
<input type="submit"></input>
</form>
'
;
if ( 
count($_GET) ){
 
$mail '';
 foreach ( 
$_GET as $var => $val $mail .= $var ' -> ' $val "\n";
 
mail'webmaster@example.com''Mail from the site!'$mail );
}
?>


This example will send with email to webmaster@example.com whatever you put in the form. You can change the form to whatever you like and it will still work.

Hope that helped Smiley

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6349
38918 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Feb 13, 2007, 06:17:57 PM »

ok do this :

Code:
<?php
echo '<form method="get" action="' $_SERVER['PHP_SELF'] . '">
<input type="text" name="variable1"></input>
<input type="text" name="variable2"></input>
<input type="submit"></input>
</form>
'
;
if ( 
count($_GET) ){
 
$mail '';
 foreach ( 
$_GET as $var => $val $mail .= $var ' -> ' $val "\n";
 
mail'webmaster@example.com''Mail from the site!'$mail );
}
?>


This example will send with email to webmaster@example.com whatever you put in the form. You can change the form to whatever you like and it will still work.

Hope that helped Smiley

Thats the same snipped I posted above Cheesy


Last blog : Upload images for usage in TinyMCE
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #10 on: Feb 13, 2007, 06:21:28 PM »

LOL. It looks that we php-think the same way Wink

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #11 on: Feb 13, 2007, 06:26:10 PM »

OK, First I want to say that I wish that I php-thought like the 2 of you.  Maybe one day it will come....

It started working!!! YEAH!!! Thanks so much for all of your help!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #12 on: Feb 13, 2007, 06:28:33 PM »

You are welcome Wink

And I think if you keep reading and posting your questions here, you will soon be much better Wink

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #13 on: Feb 13, 2007, 06:31:30 PM »

On doing some further testing, I discovered that my check marks don't all come through, just the 1st one.  How can I fix that?

I would also like to send them to another page after they fill out the form....
« Last Edit: Feb 13, 2007, 06:55:56 PM by PHPNewbie-KY »
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #14 on: Feb 13, 2007, 07:02:27 PM »

Can you post your code?

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #15 on: Feb 13, 2007, 07:10:03 PM »

Happily....

Code:
<?php
echo '<form method="get" action="' $_SERVER['PHP_SELF'] . '">
<table border="0">
<tr>
<td>Name:*</td> 
<td><input type="text" name="Name"></td>
</tr>
<tr>
<td>Company:</td>  
<td><input type="text" name="Company"></td>
</tr>
<tr>
<td>Title:</td>   
<td><input type="text" name="Title"></td>
</tr>
<tr>
<td>Contact Number:</td>   
<td><input type="text" name="Number"></td>
</tr>
<tr>
<td>Email:*</td>   
<td><input type="text" name="Email"></td>
</tr>
</table>
<hr>
<b>Requesting a Quote for:</b><br>
<table border="0" cellspacing="10px">
<tr>
<td><input type="radio" name="QuoteType" value="Print_WO"> Print Design without printing</td>
<td><input type="radio" name="QuoteType" value="Web_W"> Web Design with hosting & domain name</td>
</tr>
<tr>
<td><input type="radio" name="QuoteType" value="Print_W"> Print Design with printing</td>
<td><input type="radio" name="QuoteType" value="Web_WO"> Web Design without hosting & domain name</td>
</tr>
</table>
<hr>
<h3>Print Design</h3>
<p>Please complete this section if you would like a print design quote.</p>
Item being quoted:<br>
<table border="0" cellspacing="10px">
<tr>
<td><input type="radio" name="PrintItemType" value="BC"></td> 
<td>Business Card</td>
<td><input type="radio" name="PrintItemType" value="Flyer"></td>
<td>Flyer</td>

</tr>
<tr>
<td><input type="radio" name="PrintItemType" value="2FB"></td>
<td>2-Fold Brochure</td> 
<td><input type="radio" name="PrintItemType" value="3FB"></td> 
<td>3-Fold Brochure</td>
</tr>
<tr>
<td><input type="radio" name="PrintItemType" value="PC"></td>
<td>Post Card</td>
<td><input type="radio" name="PrintItemType" value="Sign"></td> 
<td>Signs</td>
</tr>
<tr>
<td><input type="radio" name="PrintItemType" value="PA"></td>
<td>Publication Advertisment, <i>we cannot provide printing prices on this item</i>.</td>
<td><input type="radio" name="PrintItemType" value="Other"></td>
<td>Other, <i>Please indicate in comment box what type of item you are having quoted</i></td>

</tr>
</table>
<br>
Colors:<br>
If you are quoting pricing for printing please be sure to identify the colors you would like to use if you choose 2 or 3 colors in the comment box.<br>
<table border="0" cellspacing="10px">
<tr>
<td><input type="radio" name="Color" value="CMYK"></td>
<td>Full Color (CMYK)</td>
<td><input type="radio" name="Color" value="2"></td> 
<td>2 Colors</td>
</tr>
<tr>
<td><input type="radio" name="Color" value="BW"></td>
<td>Black & White or Grey Scale</td>
<td><input type="radio" name="Color" value="3"></td> 
<td>3 Colors</td>
</tr>
</table>
<br>
Answer the below question only if you would chose to have printing priced also.<br>
Quanity: <input type="text" name="Quanity1">&nbsp;&nbsp;<input type="text" name="Quanity2"><br>
<br>
<hr>
<h3>Web Design</h3>
<p>Please complete this section if you would like a web design quote.</p>
Number of Pages on Site: <input type="text" name="Pages"><br>
<br>
Maintaince Package:<br>
<table border="0" cellspacing="10px">
<tr>
<td><input type="radio" name="maint" value="Weekly"> </td>
<td>Weekly</td>
<td><input type="radio" name="maint" value="Monthly"> </td>
<td>Monthly</td>
</tr>
<tr>
<td><input type="radio" name="maint" value="AN"> </td>
<td>As Needed</td>
<td><input type="radio" name="maint" value="None"> </td>
<td>None,&nbsp;I will maintain my own site</td>
</tr>
</table>
<br>
Online Features: <br>
<table border="0" cellspacing="10px">
<tr>
<td><input type="checkbox" name="OnlineFeatures" value="PhotoAlbum"></td>
<td>Photo Album </td>
<td><input type="checkbox" name="OnlineFeatures" value="ScrollingImages"></td>
<td>Scrolling Images </td>
<td><input type="checkbox" name="OnlineFeatures" value="DDMenu"></td>
<td>Drop Down Menu </td>
</tr>
<tr>
<td><input type="checkbox" name="OnlineFeatures" value="SS"></td>
<td>Style Switcher <br><i>Please include how <br>many syles you need</i> </td>
<td><input type="checkbox" name="OnlineFeatures" value="ShoppingCart"></td>
<td>Shopping Cart </td>
<td><input type="checkbox" name="OnlineFeatures" value="GB"></td>
<td>Guest Book </td>
</tr>
<tr>
<td><input type="checkbox" name="OnlineFeatures" value="Contact"></td>
<td>Contact Form </td>
<td><input type="checkbox" name="OnlineFeatures" value="Music"></td>
<td>Music </td>
<td><input type="checkbox" name="OnlineFeatures" value="Form"></td>
<td>Form <br>(like this one) </td>
</tr>
<tr>
<td><input type="checkbox" name="OnlineFeatures" value="PWP"></td>
<td>Password Protection </td>
<td><input type="checkbox" name="OnlineFeatures" value="Admin"></td>
<td>Administrative Back end </td>
<td><input type="checkbox" name="OnlineFeatures" value="RSS"></td>
<td>RSS Feed </td>
</tr>
<tr>
<td colspan="1"><input type="checkbox" name="OnlineFeatures" value="Other"><br></td>
<td colspan="5">Other <br><i>Please specify what type feature you are looking for in the comment box.</i> </td>

</tr>
</table>
<hr>
<h3>Comments</h3>
<p>Please give us any information you feel is important, or we have requested in the comment box below so you can recieve the most accurte quote available.</p>
<TEXTAREA NAME="feedback" ROWS=15 COLS=100></TEXTAREA>
<br><br>
<input type="submit" value="Submit">&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset">
</form>'
;
if ( 
count($_GET) ){
 
$mail '';
 foreach ( 
$_GET as $var => $val $mail .= $var ' -> ' $val "\n";
 
mail'myemail@myhost.com''Free Quote Request'$mail );
}
?>

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #16 on: Feb 13, 2007, 07:15:11 PM »

This is because you have the same name for all the check boxes so the variables are overwritten.

Use different names and it will work.

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #17 on: Feb 13, 2007, 07:20:40 PM »

Thanks, what about sending them to another page after they complete the form?
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 8116
41653 credits
Members referred : 3



« Reply #18 on: Feb 13, 2007, 07:24:04 PM »

<?phpheader('Location: http://www.example.com/');

Trial and Error my two best teachers Cool
Join us @ facebook Visit through proxy

Last blog : Free Unlimited Bandwith and disk space to good to be true?
Supreme Overlord
***
Gender: Female
Posts: 149
1018 credits
Members referred : 0



« Reply #19 on: Feb 13, 2007, 07:29:39 PM »

Where should that be placed in my code?
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5992
Tags : php forms php forms