www.webdeveloper.com
Results 1 to 8 of 8

Thread: E-mail form.

  1. #1
    Join Date
    Nov 2009
    Location
    UK, Lancs
    Posts
    33

    Smile E-mail form.

    I've had a play with dreamweaver and javascript and now know how to make a form and validate the information, great. But how can I submit this information to a server using php?
    I have a server with MySQL and want to be able to have maybe a contact form on a website that sends the information that can be recalled.
    Sorry this is so general, but how can this be done please?

    Cheers in advance

  2. #2
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    This is a simple project, and a perfect gateway to more complex PHP things. The process is quite simple and can be loosely broken down into 4 or 5 steps.

    Step 1: Create a web form (and validate it!)
    http://www.tizag.com/phpT/forms.php

    Step 2: Connect the form to a MySQL Database
    http://www.tizag.com/mysqlTutorial/mysqlconnection.php

    Step 3: Write the data to the database
    http://www.tizag.com/mysqlTutorial/mysqlinsert.php

    Step 4: Email the data (sounds like this might be what you meant by 'sends the information'
    http://us3.php.net/manual/en/function.mail.php

    Step 5: Write a simple admin to recall the info.
    http://www.tizag.com/mysqlTutorial/mysqlquery.php

    All-in-all, this is a simple project and makes for a great learning experience, and I'm sure a lot of guys here would be willing to help. Why not take a stab at it with the above help, show us what you've got, and we can help.

  3. #3
    Join Date
    Apr 2007
    Posts
    1,664
    Quote Originally Posted by chaz2290 View Post
    I've had a play with dreamweaver and javascript and now know how to make a form and validate the information, great.
    If you're only validating with Javascript the circumventing your validation is as simple as turning off javascript in your browser.

    Javascript validation should only be considered a user convenience, not security. You have to revalidate the data server side with PHP after teh form is submitted.

    This is a bit more advanced, but using AJAX you can use a PHP validation function and call them with javascript and call them again after the form is submitted. You only have a single validation function to maintain, it has the convenience of javascript and the security of PHP.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  4. #4
    Join Date
    Jul 2009
    Location
    Falls Church, Va.
    Posts
    780
    To the OP:

    One tip you might find useful, hidden in a lot of documentation and I think is very pertinent to handling form data for multiple selects or checkboxes via PHP:

    In your form set the select attribute name value to name[] so upon submission PHP will store the selected options in an array named $_POST['name'].

    Example:

    HTML Code:
    <select name="options[]"> .... </select>
    Upon submit, reference all options selected via $_POST['options'] and use foreach to loop through it, or whatever you prefer.

    -jim

  5. #5
    Join Date
    Nov 2009
    Location
    UK, Lancs
    Posts
    33

    Thanks...

    Sorry for the late reply my internet has been down...

    OctoberWind,
    Thanks I'll go through the forms now and hopefully will have one up and running soon, I want to be able to get in to web design once I've done my degree and think this is important but unfortunately not covered.

    SyCo,
    I'll look in to Ajax, notice the links kindly provided by OW don't include a server side form validation which I certainly want.
    I think javascript validation will be fine for now though, this is mainly for clients and I can't see many people disabling javascript to get passed putting a correct e-mail in.

    SrWebDeveloper,

    I have no idea what any of that means! ha, sorry im really new. I'll read go through the links, learn how its done and read that again and will hopefully understand it more.

    Thanks fellas ;D

  6. #6
    Join Date
    Apr 2007
    Posts
    1,664
    Quote Originally Posted by chaz2290 View Post
    I think javascript validation will be fine for now though, this is mainly for clients and I can't see many people disabling javascript to get passed putting a correct e-mail in.
    If anyone ever sees (or can guess) the form's action aka landing page, they can launch an attack. So perhaps your client becomes disgruntled or simply wants to see how you handle such an attack so they write a simple form with some malicious code. I'd be surprised if they stay your client much longer!

    Maybe they aren't even intending to attack your server or test you. If there name is 'drop table users they might accidentally destroy your database. http://xkcd.com/327/


    There is no magic bullet to PHP form validation. However it's really quite important. Even basic validation (and sanitizing data) can stop your server being owned. I'd advise reading up a bit.

    http://lmgtfy.com/?q=php+form+validation
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  7. #7
    Join Date
    Nov 2009
    Location
    UK, Lancs
    Posts
    33
    Quote Originally Posted by SyCo View Post
    That is sooo cool, ill be using that in future!

    In all seriousness I can see where you're coming from, i'll be sure to read up once I've learnt the basics.


    Cheers

  8. #8
    Join Date
    Apr 2007
    Posts
    1,664
    heh, just having a laugh. I understand sometimes you just don't know what to google for!

    Good luck and see you around.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles