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 9 of 9

Thread: Form processing

  1. #1
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Form processing

    Can anyone help on any of the below bits for a form completion please?

    What code would you use to ensure the submitter includes the @ sign in
    the email field?

    What code would you use to ensure the submitter only used numerals in a telephone field?

    As an extra to us getting a copy of the forms contents - how do we get a copy of the form's contents sent by email to the submitter, with a little message from the webmaster.

    Any help appreciated.

    Saz.

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    ctype functions.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question

    Any help appreciated.

  • #4
    New Coder
    Join Date
    Sep 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Saz, just a quick reply: a good tutorial here:
    form processing
    and http://www.developer.com/lang/php/article.php/3468701 and many others places. Just read some basic tutorial on a good programming site.

  • #5
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question

    Many thanks Marek and Matt for the links. I must admit, I've only been into PHP for a little while, so most of the terminology is way over my head, but will keep trying.

    On one of those links, I saw the code for the numerals part, but nothing for the other 2 questions:

    What code would you use to ensure the submitter only used numerals in a telephone field?

    What code would you use to ensure the submitter includes the @ sign in
    the email field?

    As an extra to us getting a copy of the forms contents - how do we get a copy of the form's contents sent by email to the submitter, with a little message from the webmaster.

    Any help appreciated.

    Saz.

  • #6
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I guess we may need to see some code to debug and find out why your address isn't coming through correctly??

  • #7
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question

    Sorry, I should have done that before - any help would be really appreciated:


    <? ob_start(); ?>
    <HTML>
    <HEAD>
    <TITLE>Form processing with PHP</TITLE>
    </HEAD>
    <BODY BGCOLOR="#FFFFFF">


    <?

    // Check to see if the form has been submitted
    if ($_GET["submit"])
    {

    // Assign 0 to the error variable
    $Error = 0;

    // Let's extract the GET form field elements
    extract($_GET);

    // Now, we'll check to see if ANY of the form elements are blank
    if (!($name) || !($email) || !($subject) || !($message))
    {
    // at least one of the form fields are blank
    if (!($name))
    {
    $Error = 1;
    $ErrorName = 1;
    }

    if (!($email))
    {
    $Error = 1;
    $ErrorEmail = 1;
    }

    if (!($subject))
    {
    $Error = 1;
    $ErrorSubject = 1;
    }

    if (!($message))
    {
    $Error = 1;
    $ErrorMessage = 1;
    }

    } else {

    // all the form fields are filled in with data

    // email the data to an email address
    $To = "test@010805.com";
    $Subject = "Form submission";
    $Message = "Name: $name \nEmail: $email \nSubject: $subject \nMessage: $message";
    mail($To, $Subject, $Message, "From: Your@Email.com");

    // redirect to the thank you page
    header("Location: http://www.010805.com/enquiries-1/thanks.html");

    }

    }
    ?>

    <? if ($Error > 0)
    {
    // Instruct the user that an error is present
    echo "<strong>Oops, you did not fill out all required fields. Those fields are marked below.</strong> <br />";
    }
    ?>

    <form action="index.php" method="GET">
    <table width="100%">
    <tr><td align="left" width="11%">
    <? if (($Error == 1) && ($ErrorName == 1)) { echo "<font color=\"Red\">*</font>"; } ?>
    Your Name:</td>
    <td align="left" width="87%"><input type="text" name="name" size="26" value="<? echo $name; ?>"></td></tr>
    <tr><td align="left" width="11%">
    <? if (($Error == 1) && ($ErrorEmail == 1)) { echo "<font color=\"Red\">*</font>"; } ?>
    Your E-mail:</td>
    <td align="left" width="87%"><input type="text" name="email" size="26" value="<? echo $email; ?>"></td></tr>
    <tr><td align="left" width="11%">
    <? if (($Error == 1) && ($ErrorSubject == 1)) { echo "<font color=\"Red\">*</font>"; } ?> Subject:</td>
    <td align="left" width="87%"><input type="text" name="subject" size="26" value="<? echo $subject; ?>"></td></tr>
    <tr><td align="left" width="11%" valign="top">
    <? if (($Error == 1) && ($ErrorMessage == 1)) { echo "<font color=\"Red\">*</font>"; } ?>
    Message:</td>
    <td align="left" width="87%">
    <p align="left"><textarea cols="34" rows="4" name="message"><? echo $message; ?></textarea></p>
    <p align="left"><input type="submit" name="submit" value="Send Mail">&nbsp;&nbsp;
    <input type="reset" value="Reset">
    </td>
    </tr>
    </table>
    </form>

    </BODY>
    </HTML>
    <? ob_flush(); ?>
    Last edited by Saz; 09-18-2005 at 11:31 AM.

  • #8
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question

    Ooooops, just had a thought - some people might also use letters and spaces in the telephone field, so is there any php code that won't let the form submit, unless there's at least 5 numerals please?

    Any help much appreciated.

    Saz.

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Everything more complex that the ctype functions will probably require the use of regular expressions. (I suggest using something else as a tutorial though).
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

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