SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Wildomar, CA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Form Question - HELP!

    Hello, I have installed this form on a site and I am wondering what I would need to add to it so that it requires an email address before the form is submitted, and notifies the user if they forgot to add their email address. In addition, what would I need to add it I wanted the user to have the option of adding either email OR phone number? Thanks in advance for any help.

    <!-- PHP easy-form -->
    <?

    $name = $_POST["name"];
    $address = $_POST["address"];
    $city = $_POST["city"];
    $state = $_POST["state"];
    $zip = $_POST["zip"];
    $phone = $_POST["phone"];
    $email = $_POST["email"];
    $comments = $_POST["comments"];

    $today = date("M d, Y");
    $recipient = "buyersreport@sanjoserealty.net";
    $subject = "Free Buyers Report Request";
    $forminfo =
    "Name: $name\n
    Phone: $phone\n
    Email: $email\n
    Comments: $comments\n
    Form Submitted: $today\n\n";

    $formsend = mail("$recipient", "$subject", "$forminfo", "From: $email\r\nReply-to:$email");
    ?>
    <!-- end PHP easy-form -->

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would change some and add one line
    PHP Code:
    $name = (isset($_POST["name"]))?$_POST["name"]:'';
    $address = (isset($_POST["address"]))?$_POST["address"]:'';
    $city = (isset($_POST["city"]))?$_POST["city"]:'';
    $state = (isset($_POST["state"]))?$_POST["state"]:'';
    $zip = (isset($_POST["zip"]))?$_POST["zip"]:'';
    $phone = (isset($_POST["phone"]))?$_POST["phone"]:'';
    $email = (isset($_POST["email"]))?$_POST["email"]:'';
    $comments = (isset($_POST["comments"]))?$_POST["comments"]:'';
    if(empty(
    $email))
    {
     echo 
    'Please supply an email address.';//or whatever you want
    }
    else
    {
    //do the usual stuff like creating message and sending mail

    also you might wanna use regex to validate if the email adress is proper or not.

  3. #3
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)

    Lightbulb

    Here's what I came with

    PHP Code:
     $name = (isset($_POST["name"]))?$_POST["name"]:'';
    $address = (isset($_POST["address"]))?$_POST["address"]:'';
    $city = (isset($_POST["city"]))?$_POST["city"]:'';
    $state = (isset($_POST["state"]))?$_POST["state"]:'';
    $zip = (isset($_POST["zip"]))?$_POST["zip"]:'';
    $phone = (isset($_POST["phone"]))?$_POST["phone"]:'';
    $email = (isset($_POST["email"]))?$_POST["email"]:'';
    $comments = (isset($_POST["comments"]))?$_POST["comments"]:'';
    $i=0;
    while (
    $i<strlen($phone) && (strpos($phone[$i],"0123456789")===true)) 
    $i++;
    if (
    $i<strlen($phone)-1)  $a=true;

    if(empty(
    $email) && empty($phone))
    {
    echo 
    'Please supply you e-mail address or your phone number.';//or anything you want
    }
    else if (
    $a) echo "Phone number must contain numbers only";
    else {
    {
    //finish off


  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Wildomar, CA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I tried yours first jaswinder_rana, and I made the changes to my form-send.php file and when I entered the from it still submitted but just added the words "Please supply an email address" to the thank you page.

    I tried the next suggestion second, and it came up with a parse error.

    Here is the site: www.sanjoserealty.net. When you see the fly in ad make sure you click on the top add, because that one is set up to go to me for testing right now.

    Do I need to add anything to actual form, or only to the form-send.php file?

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please post what the error is and the code..
    if you want us to check their then can please give a direct link to the page or state clearly where have to click as i could find any fly ad or something like.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Wildomar, CA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the page directly with my original code that does not require the email address: http://www.sanjoserealty.net/flyindata.htm

  7. #7
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as you know can't see php code. so you HAVE TO POST your code here.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Wildomar, CA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the php code:

    <!-- PHP easy-form -->
    <?

    $name = $_POST["name"];
    $address = $_POST["address"];
    $city = $_POST["city"];
    $state = $_POST["state"];
    $zip = $_POST["zip"];
    $phone = $_POST["phone"];
    $email = $_POST["email"];
    $comments = $_POST["comments"];


    $today = date("M d, Y");
    $recipient = "buyersreport@sanjoserealty.net";
    $subject = "Free Buyers Report Request";
    $forminfo =
    "Name: $name\n
    Phone: $phone\n
    Email: $email\n
    Comments: $comments\n
    Form Submitted: $today\n\n";

    $formsend = mail("$recipient", "$subject", "$forminfo", "From: $email\r\nReply-to:$email");
    ?>
    <!-- end PHP easy-form -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="ECE6D8">
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <td height="309">
    <p align="center"><strong>Thank you. You Should Receive Your

    FREE Report
    Shortly.</strong></p><br><br>
    <p align="center">
    <input TYPE="button" VALUE="Close Window"

    onClick="window.close()">
    </p>
    </tr>
    </table>
    </body>
    </html>

  9. #9
    SitePoint Addict toggg's Avatar
    Join Date
    Jan 2005
    Location
    Auvergne/France
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He, what's that ?
    Is it your code ?
    Try to put [php] before code and [/php] after
    so we can read it.
    Where is your <FORM>...</FORM> ?
    Or is Easy-PHP something I don't know ?
    bertrand Gugger toggg.com linux, PHP, Auvergne/France open source

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Wildomar, CA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code that is on the page and the code to my form-send.php file is listed below that:

    <!--
    Copyright (C) 2004 CentralFloridaVA.com. All rights reserved.

    PHPeasy-form version 1.1
    Released 2004-10-02

    This file is part of PHPeasy-form.

    PHPeasy-form is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    PHPeasy-form is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PHPeasy-form; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

    Contact CentralFloridaVA.com at:
    http://www.CentralFloridaVA.com

    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    -->

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Request Free Report</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="5C81B6">
    <form action="form-send.php" method="post">
    <p align="left"><strong>Request Free Buyers Report! - <font color="#FFFFFF">Emailed
    To You Immediately</font><br>
    </strong><font size="2"><em>We will not give out your email or personal information.</em></font>
    </p>
    <table width="400" border="0" cellspacing="0" cellpadding="5">
    <tr valign="top">
    <td width="20%"><strong>Name</strong></td>
    <td> <input type="text" name="name"></td>
    </tr>
    <tr valign="top">
    <td><strong>Phone</strong></td>
    <td> <input type="text" name="phone"></td>
    </tr>
    <tr valign="top">
    <td><strong>Email</strong></td>
    <td> <input type="text" name="email"></td>
    </tr>
    <tr valign="top">
    <td><strong>Comments</strong></td>
    <td> <textarea name="comments" cols="35" rows="5" id="comments"></textarea></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input type="submit" name="Submit" value="Submit">
    <input name="Reset" type="reset" id="Reset" value="Reset">
    </div></td>
    </tr>
    </table>
    </form>
    </body>
    </html>


    form-send.php code below


    <!-- PHP easy-form -->
    <?

    // Copyright (C) 2004 CentralFloridaVA.com. All rights reserved.

    // PHPeasy-form version 1.1
    // Released 2004-10-02

    // This file is part of PHPeasy-form.

    // PHPeasy-form is free software; you can redistribute it and/or modify
    // it under the terms of the GNU General Public License as published by
    // the Free Software Foundation; either version 2 of the License, or
    // (at your option) any later version.

    // PHPeasy-form is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    // GNU General Public License for more details.

    // You should have received a copy of the GNU General Public License
    // along with PHPeasy-form; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

    // Contact CentralFloridaVA.com at:
    // http://www.CentralFloridaVA.com

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++$name = <!-- PHP easy-form -->
    <?

    $name = $_POST["name"];
    $address = $_POST["address"];
    $city = $_POST["city"];
    $state = $_POST["state"];
    $zip = $_POST["zip"];
    $phone = $_POST["phone"];
    $email = $_POST["email"];
    $comments = $_POST["comments"];


    $today = date("M d, Y");
    $recipient = "email@myemail.com";
    $subject = "Free Buyers Report Request";
    $forminfo =
    "Name: $name\n
    Phone: $phone\n
    Email: $email\n
    Comments: $comments\n
    Form Submitted: $today\n\n";

    $formsend = mail("$recipient", "$subject", "$forminfo", "From: $email\r\nReply-to:$email");
    ?>
    <!-- end PHP easy-form -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="ECE6D8">
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <td height="309">
    <p align="center"><strong>Thank you. You Should Receive Your

    FREE Report
    Shortly.</strong></p><br><br>
    <p align="center">
    <input TYPE="button" VALUE="Close Window"

    onClick="window.close()">
    </p>
    </tr>
    </table>
    </body>
    </html>

  11. #11
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly is the problem?

  12. #12
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to check if it is empty, Here is a suggestion.

    PHP Code:
    if($act =="")
    {
    switch(
    $_GET['act'])
    {
    default:

    // Put the Form Code Here - Have the form's "Action" direct to something like form.php?act=check

    break;

    case
    "check":

    $name $_POST["name"]; 
    $address $_POST["address"]; 
    $city $_POST["city"]; 
    $state $_POST["state"]; 
    $zip $_POST["zip"]; 
    $phone $_POST["phone"]; 
    $email $_POST["email"]; 
    $comments $_POST["comments"]; 

    // Empty Feilds
    if(empty($email)){
    Echo
    "Your email address is required. Click <a href=''>here</a> to go back.";
    exit;
    }

    $today date("M d, Y");
    $recipient "buyersreport@sanjoserealty.net";
    $subject "Free Buyers Report Request";
    $forminfo =
    "Name: $name\n
    Phone: 
    $phone\n
    Email: 
    $email\n
    Comments: 
    $comments\n
    Form Submitted: 
    $today\n\n";

    $formsend mail("$recipient""$subject""$forminfo""From: $email\r\nReply-to:$email");
    break;
    }
    }
    ?>

    <!-- The rest of the site--> 
    Please note: Once the text is outputted that the email address is empty, it will "Kill" the code from so on. So please note that if you want to do more "Checks" and do not want to kill it yet, do something else.

    But, using the case's and switches allow you to break away without exiting etc.

    Also - Remember, the form actions "?act=" has to be the case as the case"": or it will not work. Some smarter person will probably come in here and say i'm wrong, but thats okay lol

  13. #13
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    US
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is the different between?
    $name = (isset($_POST["name"]))?$_POST["name"]:'';

    and
    $name = isset($POST["name"]);

    i usually to use the second way.

  14. #14
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by fisher318
    I tried the next suggestion second, and it came up with a parse error.
    Sorry here's it again
    PHP Code:
       <?
        $name 
    = (isset($_POST["name"]))?$_POST["name"]:'';
    $address = (isset($_POST["address"]))?$_POST["address"]:'';
    $city = (isset($_POST["city"]))?$_POST["city"]:'';
    $state = (isset($_POST["state"]))?$_POST["state"]:'';
    $zip = (isset($_POST["zip"]))?$_POST["zip"]:'';
    $phone = (isset($_POST["phone"]))?$_POST["phone"]:'';
    $email = (isset($_POST["email"]))?$_POST["email"]:'';
    $comments = (isset($_POST["comments"]))?$_POST["comments"]:'';
    $i=0;
    while (
    $i<strlen($phone) && (strpos($phone[$i],"0123456789")===true))
    $i++;
    if (
    $i<strlen($phone)-1)  $a=true;

    if(empty(
    $email) && empty($phone))
    {
    echo 
    'Please supply your e-mail address or your phone number.';//or anything you want
    }
    else if (
    $a) echo "Phone number must contain numbers only";
    else {

    //finish off
    }
    ?>

  15. #15
    SitePoint Evangelist
    Join Date
    Sep 2004
    Location
    Oregon
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Darken - You should change
    PHP Code:
    if(empty($email) && empty($phone)) 

    echo 
    'Please supply your e-mail address or your phone number.';//or anything you want 

    - To -
    PHP Code:
    if(empty($email) || empty($phone)) 

    echo 
    'Please supply your e-mail address or your phone number.';//or anything you want 

    Due to that if either of them are empty, they want to display the message. That does it will only display if BOTH are blank.

  16. #16
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)

    Wink

    Quote Originally Posted by fisher318
    I wanted the user to have the option of adding either email OR phone number?
    medicjoe95, I don't agree look what he wants email OR phone number

  17. #17
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Wildomar, CA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok Dark, thanks for your continued help. I added your code as you see below, and now I get an error that reads: Parse error: parse error in /var/www/html/form-send.php on line 86

    Any suggestions?

    <!-- PHP easy-form -->
    <?

    // Copyright (C) 2004 CentralFloridaVA.com. All rights reserved.

    // PHPeasy-form version 1.1
    // Released 2004-10-02

    // This file is part of PHPeasy-form.

    // PHPeasy-form is free software; you can redistribute it and/or

    modify
    // it under the terms of the GNU General Public License as

    published by
    // the Free Software Foundation; either version 2 of the License,

    or
    // (at your option) any later version.

    // PHPeasy-form is distributed in the hope that it will be

    useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    // GNU General Public License for more details.

    // You should have received a copy of the GNU General Public

    License
    // along with PHPeasy-form; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA

    02111-1307 USA

    // Contact CentralFloridaVA.com at:
    // http://www.CentralFloridaVA.com

    //

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    $name = (isset($_POST["name"]))?$_POST["name"]:'';
    $address = (isset($_POST["address"]))?$_POST["address"]:'';
    $city = (isset($_POST["city"]))?$_POST["city"]:'';
    $state = (isset($_POST["state"]))?$_POST["state"]:'';
    $zip = (isset($_POST["zip"]))?$_POST["zip"]:'';
    $phone = (isset($_POST["phone"]))?$_POST["phone"]:'';
    $email = (isset($_POST["email"]))?$_POST["email"]:'';
    $comments = (isset($_POST["comments"]))?$_POST["comments"]:'';
    $i=0;
    while ($i<strlen($phone) &&

    (strpos($phone[$i],"0123456789")===true))
    $i++;
    if ($i<strlen($phone)-1) $a=true;

    if(empty($email) && empty($phone))
    {
    echo 'Please supply your e-mail address or your phone number.';//or

    anything you want
    }
    else if ($a) echo "Phone number must contain numbers only";
    else {


    $today = date("M d, Y");
    $recipient = "email@mydomain.com";
    $subject = "Free Buyers Report Request";
    $forminfo =
    "Name: $name\n
    Phone: $phone\n
    Email: $email\n
    Comments: $comments\n
    Form Submitted: $today\n\n";

    $formsend = mail("$recipient", "$subject", "$forminfo", "From:

    $email\r\nReply-to:$email");
    ?>
    <!-- end PHP easy-form -->
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html;

    charset=iso-8859-1">
    </head>

    <body bgcolor="ECE6D8">
    <table width="100%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <td height="309">
    <p align="center"><strong>Thank you. You Should Receive Your

    FREE Report
    Shortly.</strong></p><br><br>
    <p align="center">
    <input TYPE="button" VALUE="Close Window"

    onClick="window.close()">
    </p>
    </tr>
    </table>
    </body>
    </html>
    Last edited by fisher318; Jan 29, 2005 at 15:00.

  18. #18
    The Mind's I ® silver trophy Dark Tranquility's Avatar
    Join Date
    Sep 2003
    Location
    KSA - UAE
    Posts
    9,457
    Mentioned
    8 Post(s)
    Tagged
    1 Thread(s)
    what is line 86 for you? in your editor I mean !! by the way what is it ?
    for me line 86 is <title>Untitled Document</title> ?

  19. #19
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are missing many }(curly brackets).

    you din't put any brackets after while and you din't close your else. just make sure all the brackts


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
  •