Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Senior Member kade119's Avatar
    Join Date
    Feb 2007
    Location
    USA
    Posts
    532
    Member #
    14888
    Liked
    1 times
    I have the php so it displays an error on a new page, .. im very new to php.. trying to follow some basic tutorials.. well i need the errors do display on the same page as the contact form, maybe say invalid e-mail below the form instead of on a new page .. here is my code

    PHP Code:
    <?php
     
    $name 
    $_POST['name'];
    if ( empty(
    $name) ) {
    echo 
    'You did not enter your name, please <a href="contact.html">go back</a> and make sure you enter it';
    die();
    }
    $company $_POST['company'];
    $email $_POST['email'];
    if ( empty(
    $email) ) {
    echo 
    'You did not enter your email address, please <a href="contact.html">go back</a> and make sure you enter it';
    die();
    }
    $tel $_POST['tel']; 
    $fax $_POST['fax'];
    $subject $_POST['subject'];
    $comments $_POST['comments'];
    if ( empty(
    $comments) ) {
    echo 
    'You did not enter any comments, please <a href="contact.html">go back</a> and make sure you enter it';
    die();
    }
    $message 'Someone has filled out the contact form on your website' "\n\n";
    $message .= 'Name: ' $name "\n";
    $message .= 'Company Name: ' $company "\n";
    $message .= 'Email Address: ' $email "\n";
    $message .= 'Telephone: ' $phone "\n";
    $message .= 'Comments: ' "\n";
    $message .= $comments;
    $sendTo 'myemail@yahoo.com';
    $Bcc 'myemail@yahoo.com';
    $headers 'From: Contact Form <' $email '>' "\r\n" 'Reply-To: ' $email "\r\n" 'Bcc: ' $Bcc "\r\n";
    mail($sendTo$subject$message$headers);
    header ("Location: thankyou.html");
    ?>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,733
    Member #
    5580
    Liked
    718 times
    On the page with your form, you'll need to give that page a .php extension
    and do some PHP scripting on that page to get back all of the original form
    variables, the error message .... then, redisplay that page with the values
    filled-in. This involves more coding than can be described here.

    You can't just go back to the form page with an error message, as the original
    variable values will be gone. You have to bring those back with you, either by
    passing them in the URL, or using PHP sessions (a deeper topic).

    Although it's great to use PHP to validate form variables before processing,
    I always like to use Javascripting directly on my form page to validate everything
    before they are allowed to submit the form.

    Here is an example of a good Javascript validation I've used before:
    http://www.massimocorner.com/validat...es/generic.htm

    Keep in mind that people can of course turn off Javascripting ... but you can
    also validate important things within the PHP script. Most of the forms I use
    aren't that important - and Javascript validation is intuitive and works nice.

    The "massimocorner" validation also has the really nice "compare" feature, where
    you ask someone to enter the email address twice to verify they typed correctly.


  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    I never do PHP form validation anymore... it's too much of a pain in the ***. Instead, I use a derivation of this script I made: http://www.webdesignforums.net/showt...orm+validation

    Then, I use database constraints to enforce data integrity, and if someone tries to hack past the javascript error message to be a pain in the ***, they get a database error... less work on my part and an easier interface.


  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,733
    Member #
    5580
    Liked
    718 times
    I guess it all depends on what the form is ...

    how important the information is ...

    If it's a contact form that will email some simple question or comment,
    I don't even bother with anything other than Javascripting. If someone
    wants to bypass it, the PHP script will simply throw it out without any message.

    Kade should know that you shouldn't let anyone enter the subject of the email,
    and control should be placed on making sure there is only one email address and
    no CC or BCC ... doing some PHP validating to clean-up any spamming type issues.


  6. #5
    Senior Member kade119's Avatar
    Join Date
    Feb 2007
    Location
    USA
    Posts
    532
    Member #
    14888
    Liked
    1 times
    mlseim thanksf or the site.. it was helpful.. so that was only js involved in that so... i still need to use PHP for security precautions?

    or do you use PHP incase js is turned off?
    any examples on this?
    thanks

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,733
    Member #
    5580
    Liked
    718 times
    Kade ...

    No need to use PHP unless you really need to control some variables
    for a database, or some other specific requirement.

    There are some PHP examples (I can't find them now) to grab only the
    first email address (if they enter in more than one). You will create the
    $subject yourself in your PHP script ... don't let anyone do that themselves.

    Other than that, for a simple "contact me" form, not much security needed.

    You could look into some PHP Captcha scripts, for spamming issues.

    I would try it out for a while and see if spamming becomes an issue or not.

    People talk about users who have Javascripting turned off ... I don't know why
    anyone would do that myself. I wouldn't worry about that.


  8. #7
    Senior Member kade119's Avatar
    Join Date
    Feb 2007
    Location
    USA
    Posts
    532
    Member #
    14888
    Liked
    1 times
    thanks.. ill go ahead and use that tmt script then.. it seemed structured well

    but i could use php to verify the form again before it sent , right?

    like if the js misssed something the php could catch the error?

    how do i set the form not to send unless the js has validated it? b/c right now when i push submit , i see the required and then it begins to submit anyways

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,733
    Member #
    5580
    Liked
    718 times
    Give us a link to your form page and let me see it in action.
    I'll see if you have something set wrong.

    It should not submit unless it's correct.


  10. #9
    Senior Member kade119's Avatar
    Join Date
    Feb 2007
    Location
    USA
    Posts
    532
    Member #
    14888
    Liked
    1 times
    http://www.kreativ.cn/contact.html

    sorry.. im trying to learn alot of this.. i lost my programmer, who was doing free lance w/ me

  11. #10
    Senior Member kade119's Avatar
    Join Date
    Feb 2007
    Location
    USA
    Posts
    532
    Member #
    14888
    Liked
    1 times
    heh if you see anything else that might need fixed.. if you have time.. like on the js that sets the date or imports my flash.. let me know =)


    nvm on the date, must be my browser settings


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:56 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com