Posted 24 November 2009

Help with info on script for a form

I am doing a website for a friend for their business & they have asked me to include a form on one of the pages to send information to them.

I can design the website but I know nothing about forms, I've looked at cgi , asp & form input and I have now done the form in the webpage but I need to know the script command to send the info through via the server, can anyone give me an idiots guide as I've seen so many form input commands I don't know which is the right one to use!

eg



Community Updates
New Comment

20 Comments

sorted by
's avatar
  1. deleted61549's avatar
    gRoberts12;6987453

    Question is, what is the form meant to do? Are you wanting to insert data … Question is, what is the form meant to do? Are you wanting to insert data into the database, send an email etc?



    this is what I did and it worked

    put a form in your webpage as below:


    Fields marked (*) are required


    Email:*



    Name:



    Tel:



    Enquiry:








    When the user clicks submit this goes to contact.php so you also need to upload a file called contact.php as below

    <?php

    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = "your@emailaddress.com";
    $Subject = "Website Enquiry";
    $Name = Trim(stripslashes($_POST['Name']));
    $Tel = Trim(stripslashes($_POST['Tel']));
    $Enquiry = Trim(stripslashes($_POST['Enquiry']));

    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (!$validationOK) {
    print "";
    exit;
    }

    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "EmailFrom: ";
    $Body .= $EmailFrom;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Enquiry: ";
    $Body .= $Enquiry;
    $Body .= "\n";

    // sends email
    $success = mail($EmailTo, $Subject, $Body, "From: ");

    if ($success){
    print "";
    }
    else{
    print "";
    }
    ?>

    I also have a page called error.htm which will redirect if there is a problem and a ok.htm which redirects to once the form has been submitted ok
  2. wolf359's avatar
    it depends on their server what type it supports. most hosts provide a cgi script to handle this sort of thing
  3. lyzzys321's avatar
    Author
    wolf359;6987335

    it depends on their server what type it supports. most hosts provide a … it depends on their server what type it supports. most hosts provide a cgi script to handle this sort of thing



    there is a cgi-bin folder on the server but there is only one file called test.cgi

    What command do I put in the actual form though if I use the cgi-bin
  4. gRoberts12's avatar
    Question is, what is the form meant to do? Are you wanting to insert data into the database, send an email etc?
  5. lyzzys321's avatar
    Author
    gRoberts12;6987453

    Question is, what is the form meant to do? Are you wanting to insert data … Question is, what is the form meant to do? Are you wanting to insert data into the database, send an email etc?



    it's is going to collect information on name, address, tel, etc & then there is a selection list that gives info on what courses are available & I've set that section as radio buttons so 1 or more can be selected as required. This information then needs to get to the business owner which ever way is easiest.
  6. lyzzys321's avatar
    Author
    dave_lunt2;6987514

    this is what I did and it workedput a form in your webpage as … this is what I did and it workedput a form in your webpage as below:Fields marked (*) are required Email:* Name:Tel:Enquiry:When the user clicks submit this goes to contact.php so you also need to upload a file called contact.php as below$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "your@emailaddress.com";$Subject = "Website Enquiry";$Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Enquiry = Trim(stripslashes($_POST['Enquiry'])); $validationOK=true;if (Trim($EmailFrom)=="") $validationOK=false;if (!$validationOK) { print ""; exit;}$Body = "";$Body .= "Name: ";$Body .= $Name;$Body .= "\n";$Body .= "EmailFrom: ";$Body .= $EmailFrom;$Body .= "\n";$Body .= "Tel: ";$Body .= $Tel;$Body .= "\n";$Body .= "Enquiry: ";$Body .= $Enquiry;$Body .= "\n";// sends email$success = mail($EmailTo, $Subject, $Body, "From: ");if ($success){ print "";}else{ print "";}?>I also have a page called error.htm which will redirect if there is a problem and a ok.htm which redirects to once the form has been submitted ok



    Does this work with radio buttons or just text fields? There is about 18 different courses they offer & the user needs to select which ones they want more information on so the business knows which ones they are interetsed in.
  7. deleted61549's avatar
    Not sure I'll try and see if it will for you
  8. deleted61549's avatar
    Can they only select one course or multiple courses?
  9. lyzzys321's avatar
    Author
    dave_lunt2;6987592

    Not sure I'll try and see if it will for you



    thank you so much for this, I've spent hours this afternoon looking at this
  10. MrBrightside1987's avatar
    When you create form the beggining in HTML looks something like this...


    The action bit, in this case someaction.php has to be an actual PHP file which you code to handle what to do when the form data is submitted.

    For a complete newbie to all this, I'd either recommend checking out the tutorials on ]W3Schools
    Otherwise I'd recommend paying someone to do a proper job of it - should cost no more than £20

    If you're lucky you'll also get someone willing to do it for a bit of rep on here.
  11. lyzzys321's avatar
    Author
    dave_lunt2;6987623

    Can they only select one course or multiple courses?



    they can select whatever they require so could be 1 or could be all 18 or anything in between!
  12. lyzzys321's avatar
    Author
    MrBrightside1987;6987646

    When you create form the beggining in HTML looks something like … When you create form the beggining in HTML looks something like this...The action bit, in this case someaction.php has to be an actual PHP file which you code to handle what to do when the form data is submitted.For a complete newbie to all this, I'd either recommend checking out the tutorials on ]W3SchoolsOtherwise I'd recommend paying someone to do a proper job of it - should cost no more than £20If you're lucky you'll also get someone willing to do it for a bit of rep on here.



    Thanks for that, I've been looking at that website but not at the php stuff, I was looking at asp & html form tags.

    I'm doing the website free of charge as it's my neighbours business, she said if I couldn't sort it out then she would just have an email link requesting the user to email her, just thought it would be better if I could get it set up for her to help her out.
  13. deleted61549's avatar

    Okay you'll be better off with check boxes as this allows the user to select multiple courses, a radio button is for one or the other usually like male or female

    set up a form like by copying and pasting this into your webpage

    Name:E-Mail: Geography Maths EnglishMessage:



    Then set up a new page and paste the following (edit field to with your own email address) and save the page as contact.php

    if(isset($_POST['submit'])) {$to = "your@emailaddress.com";$subject = … if(isset($_POST['submit'])) {$to = "your@emailaddress.com";$subject = "Enquiry";$name_field = $_POST['name'];$email_field = $_POST['email'];$message = $_POST['message'];foreach($_POST['check'] as $value) {$check_msg .= "Checked: $value\n";}$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";echo "Data has been submitted to $to!";mail($to, $subject, $body);} else {echo "blarg!";}?>



    Upload both files to your server and give it a test, then you can add remove fields etc, just get it so it is working first
  14. lyzzys321's avatar
    Author
    dave_lunt2;6987871

    Okay you'll be better off with check boxes as this allows the user to … Okay you'll be better off with check boxes as this allows the user to select multiple courses, a radio button is for one or the other usually like male or femaleset up a form like by copying and pasting this into your webpageThen set up a new page and paste the following (edit field to with your own email address) and save the page as contact.phpUpload both files to your server and give it a test, then you can add remove fields etc, just get it so it is working first



    Just copied & pasted the 1st part into the body of a blank page & changed the email address, also saved the contacts.php & when I submit I am getting this message

    Data has been submitted to ****@********.com! PHP Notice: Undefined variable: check_msg in D:\websites\**********\www\contact.php on line 13 PHP Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in D:\websites\***********\www\contact.php on line 20

    what does that mean? obviously something to do with the contact.php but I'm not sure what.

    I still haven't received the email yet either

    EDIT just re-read you post again! I forgot to change the "to" part in the contact.php :roll: just off to do that now

    2nd EDIT I did actually change the top part to my email address where it shows as

    <?php
    if(isset($_POST['submit'])) {


    $to = "your@emailaddress.com";


    should I have changed anything else or just that part?
  15. deleted61549's avatar
    lyzzys321;6988303

    Just copied & pasted the 1st part into the body of a blank page & changed … Just copied & pasted the 1st part into the body of a blank page & changed the email address, also saved the contacts.php & when I submit I am getting this message Data has been submitted to ****@********.com! PHP Notice: Undefined variable: check_msg in D:\websites\**********\www\contact.php on line 13 PHP Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in D:\websites\***********\www\contact.php on line 20 what does that mean? on line 13 I have:- E-Mail: & line 20 is:- I still haven't received the email yet either



    have you actually uploaded it to a server or are you trying it from your PC

    you need to upload these files to your website then go to the actual page for example

    --mysite.com/con…l--

    also the html page is telling it to submit to contact.php not contacts.php as you have put above, just in case that is it
  16. lyzzys321's avatar
    Author
    dave_lunt2;6988399

    have you actually uploaded it to a server or are you trying it from your … have you actually uploaded it to a server or are you trying it from your PCyou need to upload these files to your website then go to the actual page for example--www.mysite.com/contactuspage.html--also the html page is telling it to submit to contact.php not contacts.php as you have put above, just in case that is it



    yep I uploaded them to the server & I did save as contact.php not contacts.php
  17. wolf359's avatar
    above code worked fine for me. i haven't had a test email from it yet but thats nothing new for my email

    did you actually load the form from the server and not locally? you not only need to upload them but you can't test them locally either
  18. lyzzys321's avatar
    Author
    wolf359;6989569

    above code worked fine for me. i haven't had a test email from it yet but … above code worked fine for me. i haven't had a test email from it yet but thats nothing new for my email :)did you actually load the form from the server and not locally? you not only need to upload them but you can't test them locally either



    I did upload it to the server, I will try doing the two files again, it must be something I did if it works for you.

    Just to carify the only thing I need to change is the email address near the top within the contact.php
  19. wolf359's avatar
    i'm not doubting you uploaded it but did you actually run it from the server? as in going onto the net and entering the url for its location on the server.

    i still haven't rec'd the test maili sent so its possible the script isn't fully functional or more likely my crappy email
  20. lyzzys321's avatar
    Author
    wolf359;6992169

    i'm not doubting you uploaded it but did you actually run it from the … i'm not doubting you uploaded it but did you actually run it from the server? as in going onto the net and entering the url for its location on the server.i still haven't rec'd the test maili sent so its possible the script isn't fully functional or more likely my crappy email



    Fairly sure I did, not had much chance to do anything since I last logged on as been I've out, will have another look at it now, thanks for your help
's avatar