Web Analytics Made Easy -
StatCounter Help with emailing form information with php please - CodingForum

Announcement

Collapse
No announcement yet.

Help with emailing form information with php please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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( "fe[email protected]", "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; Aug 22, 2011, 08:55 AM.

  • #2
    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

    Comment


    • #3
      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.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎