Professional Web Applications Themes

Create mail/contact form - PHP Development

I tried to create an email/contact form but i'am stuck. (i'am a php-newbie) Let me explain (sorry for my bad english, it's not my native language) I have a form with the required fields and the necessary php-code. There's also some code to validate if a field is empty or there's an invalid email address. But how can i display error messages (e.g. empty field), in this (same) form. (e.g. at the top of the page) I searching fore several day's but can't find an example. I appreciate some help or example if possible, Stephanie...

  1. #1

    Default Create mail/contact form

    I tried to create an email/contact form but i'am stuck. (i'am a php-newbie)
    Let me explain (sorry for my bad english, it's not my native language)

    I have a form with the required fields and the necessary php-code.
    There's also some code to validate if a field is empty or there's an invalid
    email address.
    But how can i display error messages (e.g. empty field), in this (same)
    form. (e.g. at the top of the page)
    I searching fore several day's but can't find an example.

    I appreciate some help or example if possible,

    Stephanie


    Stephanie Guest

  2. #2

    Default Re: Create mail/contact form

    On Mon, 18 Jul 2005 13:58:11 +0200, Stephanie wrote:
     

    http://www.rent-a-tutor.com/tools/

    try the contact form generator to create a PHP-File with your contact
    form.

    Marian

    --
    Barrierefreie Online-Kurse: HTML, PHP, MySQL, Word, Excel
    http://www.lernpilot.de/wbt/
    Marian Guest

  3. #3

    Default Re: Create mail/contact form

    Stephanie wrote: 


    Something like:

    <?php

    $display_form = true;

    function validate_data()
    {
    // Here is the code that validates
    // all the data from post and if
    // there are some errors, then it proper
    // error messages and/or other error flags.
    // It returns true if data is valid and
    // false if not.
    }

    if (!empty($_POST['go']) && validate_data())
    {
    // Do data processing (eg. send mail).
    // If something goes wrong, then set proper
    // error messages and/or error flags and.
    // If everything is OK, then set $display_form
    // to false, display some confirmation message
    // and/or redirect to page which confirms
    // finishing the process.
    }

    if ($display_form)
    {
    // Here show error messages if are set.
    // And show the form (you can use some error
    // flags to point the fields which are not
    // filled properly). Use data from $_POST
    // (or $_GET) to fill the "value" attributes
    // of <input>, to display the data which
    // the user allready filled in.
    // Put some hidden value named "go", or use
    // this name on "submit" button in the form
    // so the expression "empty($_POST['go'])"
    // above would evaluate to "true" when the
    // form is submited (or resubmited).
    }

    ?>

    You can split the file above and use "include".
    Hilarion Guest

  4. #4

    Default Re: Create mail/contact form

    Creates a nice form but without the wanted error message in the same form.


    Stephanie Guest

  5. #5

    Default Re: Create mail/contact form

    I noticed that Message-ID:
    <c69c2$42db9957$513b49d4$versatel.nl> from Stephanie
    contained the following:
     

    www.ckdog.co.uk/phmail_lite

    --
    Geoff Berrow 0110001001101100010000000110
    001101101011011001000110111101100111001011
    100110001101101111001011100111010101101011
    Geoff Guest

  6. #6

    Default Re: Create mail/contact form

    I'am looking for an example that uses one form or reports errors to the main
    form.
    All these examples use at least two forms an they don't report errors to the
    main form.

    Stephanie


    Stephanie Guest

  7. #7

    Default Re: Create mail/contact form

    I noticed that Message-ID:
    <42c14$42dc8faa$513b49d4$versatel.nl> from Stephanie
    contained the following:
     

    Ah. Like this?
    http://www.ckdog.co.uk/php/form.php
    (mail sent from this form is not read)

    Code for the above
    http://www.ckdog.co.uk/php/form.zip
    --
    Geoff Berrow 0110001001101100010000000110
    001101101011011001000110111101100111001011
    100110001101101111001011100111010101101011
    Geoff Guest

  8. #8

    Default Re: Create mail/contact form

    You're great Geoff.

    This is exact what i need. I go study this example.

    Stephanie

    "There are 10 kind of people. Those who understand binary and those who
    don't."


    Stephanie Guest

  9. #9

    Default Re: Create mail/contact form

    I tried to add some e-mail vallidation but is fails.

    if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*\w+([-.]\w+)*\.\w+([-.]\w+)*/")){
    $missing[]=$req_email;
    $red[1]=" class=\"red\"";

    It only validates if the field is not empty, but not for a valid email
    address.

    Stephanie


    Stephanie Guest

  10. #10

    Default Re: Create mail/contact form

    I noticed that Message-ID:
    <258c8$42dccd76$513b49d4$versatel.nl> from Stephanie
    contained the following:
     

    Validate this: net
    Validate this: co.uk
    Validate this: com

    The first one is a black hole, the second is a typo, the third is not
    mine. All would pass as valid with a regex checker. None are valid (in
    that you won't get a reply from any of them)

    I think it's a bit pointless really. Some forms ask for the email
    address to be typed twice then compare the two which /may/ help prevent
    typos. But the only way to check if an email address is valid is to
    send mail to it, and see if you get a response.


    --
    Geoff Berrow 0110001001101100010000000110
    001101101011011001000110111101100111001011
    100110001101101111001011100111010101101011
    Geoff Guest

  11. #11

    Default Re: Create mail/contact form

    > I think it's a bit pointless really. Some forms ask for the email 

    Or check mx-records.
    But can you explain why it doesn't work :-))

    I adapted the code to use it with my own page layout. I use the form within
    a fieldset.
    The warning messages appears a the top af the page, how can i let them
    appear within my fieldset.

    (it's an instructive day :-)) )

    Stephanie


    Stephanie Guest

  12. #12

    Default Re: Create mail/contact form


    Stephanie wrote: 

    Depends on how your PHP code is arranged, but here is one way to
    achieve this - a simple form with only one field:

    <?php

    $strError = ''; // assume no errors
    $strName = '';

    if( isset( $_POST[ 'Name' ] ) )
    {
    // validate 'Name'...
    $strName = $_POST[ 'Name' ];
    if( strlen( $strName ) < 10 )
    {
    $strError = 'ERROR: Name must be at least 10 characters<br
    />';
    }
    if( $strName == 'Steve' )
    {
    $strError = 'ERROR: Your name is Steve<br />';
    }
    // ... etc ...
    }
    else
    {
    // nothing filled in yet...
    $strError = 'Please fill in all of the following values<br />';
    }

    if( $strError == '' )
    {
    // ... all ok, process the form ...
    }
    else
    {
    // print the form (again) with any user-supplied values filled
    in...
    // include error report above the form...

    ?>

    <form method="post" action="...">
    <?php print $strError; ?>
    Name: <input name="Name" type="text" value="<?php print $strName; ?>"
    />
    <input name="Save" type="submit" value=" Save " />
    </form>

    <?php

    }

    ?>

    ---
    Steve

    Steve Guest

  13. #13

    Default Re: Create mail/contact form

    Warning messages now within fieldset. (fixed)

    Still interested in validating email address (not validating if it exists,
    but if it's a valid syntax)

    Stephanie


    Stephanie Guest

  14. #14

    Default Re: Create mail/contact form


    Stephanie wrote:
     
     

    You should be getting "PHP Warning: Wrong parameter count for ereg()"
    for this snippet, as you have not specified the string to be matched!

    ---
    Steve

    Steve Guest

  15. #15

    Default Re: Create mail/contact form

    >> if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*\w+([-.]\w+)*\.\w+([-.]\w+)*/")){ 

    I already changed it this way:
    if(!$_POST['email']&&$req_email||ereg("/\w+([-+.]\w+)*\w+([-.]\w+)*\.\w+([-.]\w+)*/",
    $_POST['email'])==TRUE){

    and tried this:

    if(!$_POST['email']&&$req_email&&ereg("/\w+([-+.]\w+)*\w+([-.]\w+)*\.\w+([-.]\w+)*/",
    $_POST['email'])==TRUE){

    And this:

    if(!$_POST['email']&&$req_email){
    $missing[]=$req_email;
    $red[1]=" class=\"red\"";
    }
    if
    ($_POST['email']&&ereg("/\w+([-+.]\w+)*\w+([-.]\w+)*\.\w+([-.]\w+)*/",
    $_POST['email'])==TRUE){
    $missing[]="Use a valid email address";
    $red[1]=" class=\"red\"";
    }

    But now way.



    Stephanie Guest

  16. #16

    Default Re: Create mail/contact form

     
    .... 
    .... 
    ....
     

    Ah, I just noticed - you are using PERL compatible RE syntax with
    ereg(). If you use this syntax you must use preg_match() not ereg(). I
    still think the RE itself stinks, though 8-)

    ---
    Steve

    Steve Guest

  17. #17

    Default Re: Create mail/contact form

    I noticed that Message-ID:
    <19843$42dcea06$513b49d4$versatel.nl> from Stephanie
    contained the following:
     
    >
    >Or check mx-records.[/ref]

    Well even that won't ensure the address is read. 

    Nope, hopeless at regex.

    --
    Geoff Berrow 0110001001101100010000000110
    001101101011011001000110111101100111001011
    100110001101101111001011100111010101101011
    Geoff Guest

  18. #18

    Default Re: Create mail/contact form

    Stephanie wrote: 

    $email=eregi_replace("[^a-z0-9\.\-_]*","",$email);
    //replace any non valid characters with ""

    if(!$email == "" && (!strstr($email,"") || !strstr($email,".")))
    {
    echo $beginhtml,"e-mail ($email) is not a valid address, please correct
    it or make sure it is blank.",$endhtml;
    exit;

    HTH

    --
    TK
    http://www.wejuggle2.com/
    Still Having a Ball


    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet?




    ..

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Terry Guest

  19. #19

    Default Re: Create mail/contact form

    Thx Terry.


    Stephanie Guest

  20. #20

    Default Re: Create mail/contact form

    Stephanie wrote: 
    You may use getdnsrr() with proper keys...
    Andrzej Guest

Similar Threads

  1. How to contact a mail server?
    By Sammy S in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: July 25th, 06:57 PM
  2. How do I contact my mail server?
    By Ed in forum Mac Programming
    Replies: 4
    Last Post: December 20th, 07:03 PM
  3. E-mail contact
    By Big D in forum Macromedia Director Lingo
    Replies: 1
    Last Post: November 6th, 12:35 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139