[php] Submitting Forms - preCharge Forums
It shows that you are unregistered. Please register with us by clicking Here
preCharge Forums


Nav Green LeftNav Right
preCharge Forums > Website Design & Development > Graphics & Multimedia » [php] Submitting Forms


Reply
Tcat Right
 
LinkBack Thread Tools Display Modes Tcat Right
Old 06-13-2005   #1 (permalink)
Gaia
Senior Member
 
Join Date: Jun 2005
Location: under a rock
Age: 21
Posts: 665
Send a message via AIM to Gaia Send a message via MSN to Gaia Send a message via Yahoo to Gaia
Default

Not sure if this will be useful to anyone, but maybe the explinations will help some people with the workings of PHP.

This is how you send a form via a PHP script.

Ok, the first thing you need is the form. Which will be made with HTML.
In this form, we will ask for a name, email and comment.

Code:
<form action='send.php' method='post'>
	Name: <input type='text' name='name' /><br /><br />
	E-Mail: <input type='text' name='email' /><br /><br />
	Comment: <textbox name='comment' cols='50' rows='5'></textbox><br /><br />
	<input type='submit' value='Send' name='submit' />
</form>
Now, to break down some parts of HTML you may not be used to.

Code:
form action='send.php'
This means that once submitted, it will execute the code in the send.php file.

Code:
method='post'
That is used to carry the information through the browser.

Code:
name='email'
That is used to assign the inputted information a specific name, you'll see
where that comes up later in the PHP script.

Ok, onto the PHP script needed to send the information.

Code:
<?php

//Check to see if the submit button was hit
if (!isset($_POST['submit'])) {
	echo "You did not submit the form";

} else {

//Assign each submitted information to a variable
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];

//Assign the mail variables
$subject = "Form Submitted";
$message = "Name: $name\n\n E-mail: $email\n\n $content";
$your_email = "youremail@domain.com";

//send the mail
mail($your_email, $subject, $message);


//Tell the user that the email was successful and redirect them
echo "E-mail sent, thanks for your feedback<br />Redirecting...";
echo "<META HTTP-EQUIV = 'Refresh' Content = '2; URL = index.php'>";

}

?>
And now a further breakdown of the above code.

Code:
if (!isset($_POST['submit']))
This checks to see if the submit button was clicked. And if it was not, to display an error.

Code:
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$_POST is a pre-defined variable in PHP. the ['email'] assigns the submitted information from the text box with the name 'email'. Then, you store the information from $_POST['email'] in the $email variable.

Code:
//Assign the mail variables
$subject = "Form Submitted";
$message = "Name: $name\n\n E-mail: $email\n\n $content";
$your_email = "youremail@domain.com";

//send the mail
mail($your_email, $subject, $message);
Then, you send the submitted information in a email to your email address.

Code:
//PHP comments
Using 2 slashes (//) is how you make singl line comments in PHP, just so you know what i was doing in the above code.

And that is about all. If any part of it doesn't make sense to you just post here and i'll try to further explain

Copyright, Gaia of Eternal Realm
__________________
http://eternal-realm.net/images/sigs/knife.gif
http://img304.imageshack.us/img304/4...rlpower9rm.jpg
Do we have to die for love or do we love to die?

Please don't Instant Message or Private Message me for graphic requests. If you want a graphic made go to this forum and someone will surely help you out.

For those who give a %*#$
Gaia is offline   Reply With Quote


Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I use MY WEBSITE'S email when submitting to Dmoz? bailey All Other SE's & Directories 2 08-28-2008 05:35 PM
Listing of Business Forms... Evolution Graphics General Business Issues 3 09-01-2006 12:33 AM
Search Engine Optimization Considerations before submitting your site jordan Search Engine Optimization 0 07-28-2006 03:01 PM
Are there compatibility issues between ASP.NET and mobile Web forms? Nazir .NET 0 07-25-2006 10:28 AM
Looping through forms items clayton ASP 0 07-08-2006 06:23 PM


footer left
All times are GMT. The time now is 11:32 PM.

DISCLAIMER: preCharge Risk Management is not responsible for any opinions, advice or comments expressed on the preCharge Community Forums.
preCharge® is a registered trademark of preCharge Risk Management | chargeback protection | Merchant Account Blog

Powered by vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC6

Credit Score | Cell Phones | Mortgages | Mobile Phones | Free Ringtones

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49