Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Help with emailing form information with php please

    So I have to make this fake form for uni SA. It needs to call a php file that sends all the information as a comma delimited file so that it can be read by a database program such as Microsoft Excel.

    This is the html I've got so far:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <p><img src="unisa.jpg" width="709" height="607" alt="unisa" /></p>
    <hr />
    <form id="form1" name="form1" method="post" action="form.php">
    <table width="500" border="0">
    <tr>
    <td>YOUR NAME*:</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Family Name (as it appears on your last degree):</td>
    <td><input type="text" name="Fname" id="Fname" tabindex=1/></td>
    </tr>
    <tr>
    <td>Given Names(s):</td>
    <td><input type="text" name="Gname" id="Gname" tabindex=2/></td>
    </tr>
    <tr>
    <td><label for="gender">Male/Female:</label></td>
    <td>Male:
    <input type="radio" name="radio" id="gender" value="male" tabindex=3/>
    Female:
    <input type="radio" name="radio" id="gender" value="female" tabindex=4/></td>
    </tr>
    <tr>
    <td>YOUR FULL ADDRESS*:</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Street:</td>
    <td><input type="text" name="street" id="street" tabindex=5/></td>
    </tr>
    <tr>
    <td>City:</td>
    <td><input type="text" name="city" id="city" tabindex=6/></td>
    </tr>
    <tr>
    <td>Country:</td>
    <td><input type="text" name="country" id="country" tabindex=7/></td>
    </tr>
    <tr>
    <td>Zip Code:</td>
    <td><input type="text" name="zipcode" id="zipcode" tabindex=8/></td>
    </tr>
    <tr>
    <td>Phone*:</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Country Code:</td>
    <td><input type="text" name="pcountrycode" id="pcountrycode" tabindex=9/></td>
    </tr>
    <tr>
    <td>Area Code:</td>
    <td><input type="text" name="pareacode" id="pareacode" tabindex=10/></td>
    </tr>
    <tr>
    <td>Number:</td>
    <td><input type="text" name="pnumber" id="pnumber" tabindex=11/></td>
    </tr>
    <tr>
    <td>FAX*:</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Country Code:</td>
    <td><input type="text" name="fcountrycode" id="fcountrycode" tabindex=12/></td>
    </tr>
    <tr>
    <td>Area Code:</td>
    <td><input type="text" name="fareacode" id="fareacode" tabindex=13/></td>
    </tr>
    <tr>
    <td>Number:</td>
    <td><input type="text" name="fnumber" id="fnumber" tabindex=14/></td>
    </tr>
    <tr>
    <td>Email* (private for all correspondence):</td>
    <td><input type="text" name="email" id="email" tabindex=15/></td>
    </tr>
    <tr>
    <td>CURRENT QUALIFICATIONS* (list all awards &amp; degrees obtained and any current studies in order of date conferred):</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Award/Degree:</td>
    <td><input type="text" name="cdegree" id="cdegree" tabindex=16/></td>
    </tr>
    <tr>
    <td>Institution:</td>
    <td><input type="text" name="cinstitution" id="cinstitution" tabindex=17/></td>
    </tr>
    <tr>
    <td>Year Conferred:</td>
    <td><input type="text" name="cyear" id="cyear" tabindex=18/></td>
    </tr>
    <tr>
    <td>NEEDED QUALIFICATIONS (list all awards &amp; degrees you want help with):</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>Award/Degree:</td>
    <td><input type="text" name="ndegree" id="ndegree" tabindex=19/></td>
    </tr>
    <tr>
    <td>Institution:</td>
    <td><input type="text" name="ninstitution" id="ninstitution" tabindex=20/></td>
    </tr>
    <tr>
    <td>Year:</td>
    <td><input type="text" name="nyear" id="nyear" tabindex=21/></td>
    </tr>
    </table>
    Comments (100 words) on WHY you need to study for this award:
    <br>
    <textarea name="comments" id="comments" cols="45" rows="5" tabindex=22></textarea>
    </br>
    <br>
    <input type="submit" name="submit" id="submit" value="Send it!" tabindex=23/>
    </br>
    </form>
    </body>
    </html>
    I don't think it needs to be any better than the most basic of basic coding, meaning it doesn't need to be able to tell if everything has been filled out correctly or display any messages, but I suppose doing so would be extra credit.

    Is the php as simple as this?:

    <?php
    $email = $_REQUEST['email'] ;
    $comments = $_REQUEST['comments'] ;

    mail( "feedback@example.com", "Uni Degree Qualifications",
    $message, "From: $email" );
    ?>
    Do I put a $_REQUEST thingy for every part of the form? Is it the same code for the radio buttons and did I do the buttons correctly? How exactly do you make it "comma delimited"?

    Thanks in advance.
    Last edited by happycrab91; 08-22-2011 at 01:55 PM.

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Before I go any further I will mention that you should probably edit your post to remove the e-mail address from your post to prevent spam problems to that address.

    Now on to your questions...

    Since your method is set to "post" you should really use $_POST rather than $_REQUEST. Really, in general, you should just not use $_REQUEST. It is generally frowned upon.

    Whether you use $_REQUEST, $_GET, or $_POST the values will be stored as an array in one of those built-in variables. So you access them and treat them as arrays. Now your question says that the e-mail should send all form data in comma-delimited format but your PHP only sends comments. No other form data is being processed and sent. If you want to send more form data than just the comments then you will need to do one of two things:

    1) implode() the $_POST array variable using a comma character as your "glue." This will give you literally ALL data from the form as a comma-delimited string.

    2) loop through the $_POST array selecting only the particular keys for which you want to send data and create a comma-separated string with those valules

    Then, whichever of the above you do, pass that result to the mail function for the body text.

    Your mail function actually uses $message for the variable, but that is not yet defined in the rest of your PHP script so that will just send an e-mail without any text. Make sure that you set your comma-delimited information to use the variable name "$message" and then your mail function will come to life.

    Your radio buttons both use the same name - which is correct - but they also both use the same ID - which is incorrect from an HTML validity standpoint. It won't adversely affect the PHP performance but it's technically incorrect to use the same ID on more than one item in the same page at the same time. But since you're using a doctype it seems as though your professor might be the type who would notice so I would recommend a trip to the HTML validator to clean up whatever mess you have in the page.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    happycrab91 (08-22-2011)

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for replying pretty quickly. Thanks for the advice and tips I will try to figure it out from what you told me. If I'm too stupid to figure it out I'll ask for more help. I don't think the email is real but I changed it anyway.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •