FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need help with submitting form





freakinlame
Hey all, okay I have created a form using frontpage (maybve not the best thing to do) but now I just want the form to be submitted to my e-mail address so that I can receive what is being input into the form. How do I do that? My friend told me it requires a php script but he doesn't know how to do it. Smile
salman_500
freakinlame wrote:
Hey all, okay I have created a form using frontpage (maybve not the best thing to do) but now I just want the form to be submitted to my e-mail address so that I can receive what is being input into the form. How do I do that? My friend told me it requires a php script but he doesn't know how to do it. Smile


your friend is absolutely right !

you need php script to do that... its fairly simple...... all you need to do is set the "action" of the form to a page that contains the mail script...e.g. mail.php..

in this script you first need to recieve the data and put it inot arrays.... it might not be the best way to do it... but its what i know....

like...
the script goes...

Note: Sorry if im wrong...im new too Razz

file name should end in .php..

e.g.:
"mail.php"

Code:

<?php

// lets say your fields are name and age
// you submit button name is submit..

If ($_POST('submit') {

// making sure that script runs when form is submitted....

$name = $_POST['name'];
$age = $_POST['age'];

// other fields as:
// $yourfield = $_POST['yourfield'];

// name and age are field names in the form....

$name = stripslashes($name);
$age = stripslashes($age);

// just makin sure data makes sense..... :P

// now to send data in mail !

// Your e-mail address :
$email_address = youraddress@host.com

// Content of the mail :

$subject = "Form entry on your site ! "
$message = "You have recieved an entry on your site...

Entry contains following information:

Name : $name
Age : $age
     
";
     
// sending it ...

mail($email_address, $subject, $message, 
        "From: Your site Form<no-reply@yoursite.com>\n
        X-Mailer: PHP/" . phpversion());

// mail sent... tell the user it was successfull .
   
echo 'Your Entry has been mailed to the webmaster. Thank You !';

}

// now if the form was not submitted.... show him the form...

else {

// Show the form by including it into thae page.... enter path to form file...

include ('path/to/your/form/file.htm');

}

?>


well.. thats about it...i gues.... if anyone thinks im wrong somewhere....please correct me so this fella can make use of somthin...

you can add other fields as well... just foolow the pattern in the steps...

hope it helps.... Cool
Diablosblizz
NOTE: FrontPage does NOT deal with .php. Use Dreamweaver 8. Smile
TomS
No. But the form is html. So therefor it can be used.
Josso
I actually never thought of this, does this make MORE or LESS spam?... seeing as it's intergrated into the script.
Diablosblizz
TomS wrote:
No. But the form is html. So therefor it can be used.


Ah alright, I never knew Frontpage "reads" php. Sorry, but im a DreamWeaver type a guy, though, I always did like Frontpage (the whole 3 times i used it).

The reason I like DreamWeaver is because of the FTP, and if Frontpage has that then I would switch..But does Frontpage have the FTP type thing?
spider
If he wanted something to work with php, and wanted to try something new, and have the php in the page itself, he could try phpedit,, its free, and it does everything from css, java script, html, php, you name it, it has alot... Ive been using it for 4 years... and thats a nice tutorial salman_500, I might use that myself if you dont mind... dont know exactly what for yet,, but will think of something,, maybe for people wanting advertising...lol... thanks.
You can get phpedit from here:
http://www.nusphere.com/
mathiaus
This topic is not for discussing web editors.

@Joso: About spam, the email is never displayed on the page. The form data is sent to the server which sends it to the email specified. This means spam bots wont see any emails to pick up and collect.
You may however have other bots filling in your forms a lot, more so if you use the GET method rather than POST. To stop this, I suggest using captcha.

By the way, it doesnt require PHP, PHP just happens to the best (in my opinion) method for use in such a situation.
salman_500
spider wrote:
and thats a nice tutorial salman_500, I might use that myself if you dont mind... dont know exactly what for yet,, but will think of something,, maybe for people wanting advertising...lol... thanks.


thnx to you to... its one of my first too....lol Laughing Wink .....

i just learnt how to do it... so i thought i'd share Razz
freakinlame
thank you so much..I'll give it a try
SlowWalkere
The script looks like it should work fine. One tiny problem I could foresee, though, is if you change the form elements you'll have to change the script each time. You'll also have to write a new script for every form you want to e-mail to yourself...

You can fix this by using a bit of code to create a message body using everything stored in the $_POST array, instead of individually selecting pieces to enter.

So, for example, where $message is defined, you could use this...
Code:
$message = "You have received an entry on your website.\n
    The entry contains the following information...\n
    \n";

foreach ($_POST as $key => $val)
{
    $message .= "$key : $val \n";
}


That will cycle through the $_POST variable and add each element in a line similar to "Name : Walkere".

Also, when you actually call the mail() function and then say "You're message has been sent successful," I would do some error checking before I output that message. It is possible that the function could not run correctly but the user would think that the message was sent.

This was recently in another thread, but in short you call the mail function in an if statement. If it works, you echo the message, if not you go back to the form or do something.

Code:
if (mail( ... ))
{
    echo "Sent successfully.";
}
else
{
    // Do error stuff here
}


Good luck,
- Walkere
freakinlame
salman_500 and walkere, I don't quite understand what is needed to be done. Especially with the code that salman_500 provide. Could you teach me how can I make use of the code? Anyways, the link to the website that I'm working at which include the forms are
http://www.mcb-englishclub.frih.net/contact_forms/index.htm
and
http://www.mcb-englishclub.frih.net/feedbacks/index.htm
could you guys check it out cause I'm currently using the "mailto:" function cause I don't know how to make use of the codes you provided me. Thanks Smile
freakinlame
anyone can help me to fix my form? Please..its really urgent..
Fire Boar
Rename your form files to form.html, and make a new file called index.php (in that directory). Now, don't be offended, salman_500, but I'm completely changing the script so only one or two lines need to be changed.

Here is the script to put into index.php:

Code:

<?php

//
// Change this stuff:
//

// File where the form is located.
$formfile = "form.html";
// Location of the file to show once the user has successfully sent a message:
$successfile = "somewhere_else.html";
// Your e-mail address:
$email_address = "someone@someplace.com";
// All the fields in your form - seperate each with a colon.
$fields = "name:age";

//
// Now leave the rest alone.
//

$field_array = explode(":", $fields);
if ($_POST[$field_array[0]]) {

$array_size = count($field_array);
$message_bulk = "";
for ($i = 0, $i < $array_size, $i++)
{
if ($_POST[$field_array[$i]])
{
$message_bulk .= $field_array[$i].": ".stripslashes($_POST[$field_array[$i]])."\n";
}
}

$subject = "Form entry on your site! "
$message = "You have recieved an entry on your site...\n\nEntry contains following information:\n\n".$message_bulk."\n";

mail($email_address, $subject, $message,
        "From: Form<no-reply@mcb-englishclub.frih.net>\n
        X-Mailer: PHP/" . phpversion());

// mail sent... redirect to page telling the user it was successful.
header ("Location: ".$successfile);
}

// now if the form was not submitted.... show him the form...
else {
// Show the form by including it into the page.... enter path to form file...
include ($formfile);
}

?>


Change the stuff near the beginning of the script; it should be self-explanatory. Now all you need is a form starting like this in form.html:
Code:
<form action="" method="post">
Related topics
How did you come up with your username?
Help with upload form script! [RESOLVED]
Get page source in javascript
Please Help? CGI form mail on my site... only 2 questions!
Donate(tax deductible) to help out an intern
Uplaoding images using php form :::: Help needed
Anyone care to help me with a simple PHP Form ?
Help for sign_up form
Ajax or JS - need help ASAP
Any DIABLO 2 LOD fans out there?
help getting form info into mysql db
Direct Action To Stop The War Reemerges
Two validations process
Need Help-- Order Form in Flash
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.