How do i make my required fields required?

Discussion in 'PHP' started by drew68, Apr 10, 2008.

  1. #1
    i have my client site http://discover1031.com/ and i need to make 3 of the fields on that form required. here's the script i'm using...


    index.php
    -----------------------------------------------------------
    <?php
    $ERRstatus = false;

    $OPTfields = array();

    $REQfields = array();
    $REQfields['name'] = "Your Name";
    $REQfields['phone'] = "Phone Number";
    $REQfields['email'] = "Email Address";
    $REQfields['agent'] = "Do you have an agent or broker?";
    $REQfields['equity'] = "How much equity/debt do you need?";
    $REQfields['accommodator'] = "Do you have an accommodator?";
    $REQfields['subject'] = "Subject";
    $REQfields['comment'] = "How may we help you?";

    $LBLfields = array();
    $VALfields = array();

    IF (!isset($_POST['submitIt'])) :
    FOREACH ($REQfields as $key => $thisFIELD) :
    $LBLfields[$key] = $thisFIELD;
    ENDFOREACH;
    ELSE :
    FOREACH ($REQfields as $key => $thisFIELD) :
    IF (!isset($_POST[$key]) OR empty($_POST[$key])) :
    $ERRstatus = true;
    $LBLfields[$key] = "<font color='#FF0000'>$thisFIELD:&nbsp;</font>";
    $VALfields[$key] = "";
    ELSE :
    $LBLfields[$key] = $thisFIELD;
    $VALfields[$key] = $_POST[$key];
    ENDIF;
    ENDFOREACH;
    IF (!$ERRstatus) : // No errors noted
    procMail($REQfields, $OPTfields);
    header("Location: http://www.discover1031.com/thank_you.html");
    exit;
    ENDIF;
    ENDIF;
    ?>

    <html>
    <body>
    <form action="<?php print $_SERVER['PHP_SELF'] ?>" method="post" name="form1" id="form1">
    <tr>
    <td width="50%" bgcolor="#F5F5F5"><div align="right"><span class="content"><?php print $LBLfields['position'] ?><span class="style2">*</span> Your Name:</span></div></td>
    <td width="50%" bgcolor="#F5F5F5"><input type="text" name="name" value="<? print $VALfields['name'];?>" maxlength="60" /></td>
    </tr>
    <tr>
    <td><div align="right"><span class="content"><?php print $LBLfields['position'] ?><span class="style2">*</span> Phone Number:</span></div></td>
    <td><input type="text" name="phone" value="<? print $VALfields['phone'];?>" maxlength="60" /></td>
    </tr>
    <tr>
    <td bgcolor="#F5F5F5"><div align="right"><span class="content"><?php print $LBLfields['position'] ?><span class="style2">*</span> Email Address:</span></div></td>
    <td bgcolor="#F5F5F5"><input type="text" name="email" value="<? print $VALfields['email'];?>" maxlength="60" /></td>
    </tr>
    <tr>
    <td><div align="right"><span class="content"><?php print $LBLfields['position'] ?>Do you have an agent or broker?:</span></div></td>
    <td><input type="text" name="agent" value="<? print $VALfields['agent'];?>" maxlength="60" /></td>
    </tr>
    <tr>
    <td bgcolor="#F5F5F5"><div align="right"><span class="content"><?php print $LBLfields['position'] ?>How much equity/debt do you need?:</span></div></td>
    <td bgcolor="#F5F5F5"><input type="text" name="equity" value="<? print $VALfields['equity'];?>" maxlength="60" /></td>
    </tr>
    <tr>
    <td><div align="right"><span class="content"><?php print $LBLfields['position'] ?>Do you have an accommodator?:</span></div></td>
    <td><input type="text" name="accommodator" value="<? print $VALfields['accommodator'];?>" maxlength="60" /></td>
    </tr>
    <tr>
    <td bgcolor="#F5F5F5"><div align="right"><span class="content"><?php print $LBLfields['position'] ?>Subject:</span></div></td>
    <td bgcolor="#F5F5F5"><input type="text" name="subject" value="<? print $VALfields['subject'];?>" maxlength="60" /></td>
    </tr>
    <tr>
    <td valign="top"><div align="right"><span class="content"><?php print $LBLfields['position'] ?>How may we help you?:</span></div></td>
    <td><textarea name="comment" cols="30"><? print ((isset($_POST['comment']) AND !empty($_POST['comment']))? $_POST["comment"] : ""); ?></textarea></td>
    </tr>
    <tr>
    <td bgcolor="#F5F5F5">&nbsp;</td>
    <td bgcolor="#F5F5F5"><span class="content"><input type="submit" name="submitIt" value="Send" /></span></td>
    </tr>
    </form>

    </body>
    </html>
    <?php
    function procMail($pREQ, $pOPT) {
    $mailMessage = "";
    FOREACH ($pREQ as $key => $thisFIELD) :
    $mailMessage .= $thisFIELD . ": " . $_POST[$key] . "\n\n";
    ENDFOREACH;
    FOREACH ($pOPT as $key => $thisFIELD) :
    $mailMessage .= $thisFIELD . ": " . $_POST[$key] . "\n\n";
    ENDFOREACH;
    $mailTo = "Tenant-In-Common Contact Info <whitepacific@wp1031.com>";
    $mailFromAddr = "whitepacific@wp1031.com";
    $mailFromName = "TIC Inquirer";
    $mailFrom = "From: " . $mailFromName . "<" . $mailFromAddr . ">\r\n";
    $mailSubject = "Financial Support Form";
    return @mail($mailTo, $mailSubject, $mailMessage, $mailFrom);
    }
    ?>




    It's actually calling for this file here formMail1.php
    -----------------------------------------------------------

    <?php
    if(empty($_POST["name"])){
    $emptyStr = true;
    $nameErr = true;
    }
    if(empty($_POST["phone"])){
    $emptyStr = true;
    $phoneErr = true;
    }
    if(empty($_POST["email"])){
    $emptyStr = true;
    $emailErr = true;
    }
    if(empty($_POST["agent"])){
    $emptyStr = true;
    $agentErr = true;
    }
    if(empty($_POST["equity"])){
    $emptyStr = true;
    $equityErr = true;
    }
    if(empty($_POST["accommodator"])){
    $emptyStr = true;
    $accommodatorErr = true;
    }
    if(empty($_POST["subject"])){
    $emptyStr = true;
    $phoneErr = true;
    }
    else{
    if (strlen($_POST["comment"]) > 800)
    $myComment = substr($_POST["comment"],0,800);
    else
    $myComment = $_POST["comment"];

    }
    if(!$emptyStr)
    {
    $admin_email = 'whitepacific@wp1031.com';
    $headers1 = "From: " ;
    $sub1 = 'New comment (1031 Discover)';
    $message1 = 'name : ' .$_POST["name"] ."\r\n";
    $message1 .= 'phone: '.$_POST["phone"] ."\r\n";
    $message1 .= 'email: '.$_POST["email"] ."\r\n";
    $message1 .= 'agent: '.$_POST["agent"] ."\r\n";
    $message1 .= 'equity: '.$_POST["equity"] ."\r\n";
    $message1 .= 'accommodator: '.$_POST["accommodator"] ."\r\n";
    $message1 .= 'subject: '.$_POST["subject"] ."\r\n";
    $message1 .= 'comment: '.$myComment ."\r\n";
    mail ($admin_email, $sub1, $message1, $headers1);
    header("Location: http://www.discover1031.com/thank_you.html");
    exit;
    }
    }
    ?>
     
    drew68, Apr 10, 2008 IP
  2. Dade72

    Dade72 Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you are making this alot harder than it has to be, and this should actually be asked in the javascript section, where as everybody uses javascript to check against empty input boxes.
    The simplest way to do this is to put onsubmit="javascriptFuncion()" on the form to check it before posting.
    From there you'll use if statements to check against empty boxes (ie if(form1.name == "") then send an alert or something)
     
    Dade72, Apr 10, 2008 IP
  3. drew68

    drew68 Well-Known Member

    Messages:
    582
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #3
    the form is working fine..it's when all the fields are not filled in that we don't get the email.

    i have 3 required fields...and if the others are not filled then i won't get the email.
     
    drew68, Apr 10, 2008 IP