SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP Contact Form

    I have a PHP contact form that I am using on my new site. There are certain form fields that are required for the form to go through. There are three sections to the form: Company Information, Description of Site and Budget and Requirements.

    The required form fields work properly in the Budget and Requirements section, alerting the user that they must fill out the form fields for the form to submit. But in the Company Information section, they are not working correctly. I can forget to fill out all of the required fields in this section, and the form will still submit.

    Here is the page and here is the PHP:

    PHP Code:
    <?php #Script Title: estimateform.php
        
    if (isset($_POST['submitted'])) {
            
    // Create error array
            
    $errors = array();
            
    // Collect values and place in variables
            
    if (isset($_POST['contact'])) {
                
    $contact stripslashes($_POST['contact']);
            } else {
                
    $errors[] = 'You must list a CONTACT PERSON.';
                
    $contact NULL;
            }
            if (isset(
    $_POST['phone'])) {
                
    $phone stripslashes($_POST['phone']);
            } else {
                
    $errors[] = 'You must list a PHONE NUMBER.';
                
    $phone NULL;
            }
            if (isset(
    $_POST['company'])) {
                
    $company stripslashes($_POST['company']);
            } else {
                
    $company NULL;
            }
            if (isset(
    $_POST['email'])) {
                
    $email stripslashes($_POST['email']);
            } else {
                
    $errors[] = 'You must list an EMAIL ADDRESS.';
                
    $email NULL;
            }
            if (isset(
    $_POST['url'])) {
                
    $url stripslashes($_POST['url']);
            } else {
                
    $url "N/A";
            }
            if (isset(
    $_POST['address1'])) {
                
    $address1 stripslashes($_POST['address1']);
            } else {
                
    $address1 NULL;
            }
            if (isset(
    $_POST['address2'])) {
                
    $address2 stripslashes($_POST['address2']);
            } else {
                
    $address2 "";
            }
            if (isset(
    $_POST['city'])) {
                
    $city stripslashes($_POST['city']);
            } else {
                
    $errors[] = 'You must list a CITY.';
                
    $city NULL;
            }
            if (isset(
    $_POST['state'])) {
                
    $state stripslashes($_POST['state']);
            } else {
                
    $errors[] = 'You must list a STATE.';
                
    $state NULL;
            }
            if (isset(
    $_POST['zip'])) {
                
    $zip stripslashes($_POST['zip']);
            } else {
                
    $zip NULL;
            }
            if (isset(
    $_POST['description'])) {
                
    $description stripslashes($_POST['description']);
            } else {
                
    $errors[] = 'You must list a brief DESCRIPTION of your new site.';
                
    $description NULL;
            }
            if (isset(
    $_POST['services'])) {
                
    $services implode (', '$_POST['services']);
            } else {
                
    $errors[] = 'You must choose the SERVICES you require.';
                
    $services NULL;
            }
            if (isset(
    $_POST['numberofpages'])) {
                
    $numberofpages $_POST['numberofpages'];
            } else {
                
    $errors[] = 'You must list an approximate NUMBER OF PAGES.';
                
    $numberofpages NULL;
            }
            if (isset(
    $_POST['budget'])) {
                
    $budget $_POST['budget'];
            } else {
                
    $errors[] = 'You must choose your BUDGET amount for your new site.';
                
    $budget NULL;
            }
            if (isset(
    $_POST['when'])) {
                
    $when $_POST['when'];
            } else {
                
    $errors[] = 'You must choose WHEN YOU REQUIRE OUR SERVICES.';
                
    $when NULL;
            }
            if (isset(
    $_POST['features'])) {
                
    $features implode (', '$_POST['features']);
            } else {
                
    $errors[] = 'You must choose your REQUESTED FEATURES.';
                
    $features NULL;
            }
            if (isset(
    $_POST['howdidyouhear'])) {
                
    $howdidyouhear implode (', '$_POST['howdidyouhear']);
            } else {
                
    $howdidyouhear NULL;
            }
            
    // If there are no errors
            
    if (empty($errors)) {
                
    // Create body of email to be sent to me
                
    $body "Please respond to this person and their request for an estimate as soon as possible!\n\n";
                
    $body .= "CONTACT PERSON: $contact\n\n";
                
    $body .= "COMPANY NAME: $company\n";
                
    $body .= "ADDRESS 1: $address1\n";
                
    $body .= "ADDRESS 2: $address2\n";
                
    $body .= "CITY: $city\n";
                
    $body .= "STATE: $state\n";
                
    $body .= "ZIP CODE: $zip\n\n";
                
    $body .= "PHONE NUMBER: $phone\n";
                
    $body .= "EMAIL ADDRESS: $email\n\n";
                
    $body .= "EXISTING URL: $url\n\n";
                
    $body .= "DESCRIPTION OF SITE:\n";
                
    $body .= "$description\n\n";
                
    $body .= "WHAT SERVICES DO YOU REQUIRE?:\n";
                
    $body .= "$services\n\n";
                
    $body .= "APPROXIMATE NUMBER OF PAGES:\n";
                
    $body .= "$numberofpages\n\n";
                
    $body .= "WEBSITE BUDGET:\n";
                
    $body .= "$budget\n\n";
                
    $body .= "WHEN DO YOU REQUIRE OUR SERVICES?:\n";
                
    $body .= "$when\n\n";
                
    $body .= "REQUESTED WEBSITE FEATURES:\n";
                
    $body .= "$features\n\n";
                
    $body .= "HOW DID YOU HEAR ABOUT US?:\n";
                
    $body .= "$howdidyouhear\n\n";
                
    // Send email
                
    mail('info@jameswebdevelopment.com','Someone wants an estimate... and fast!',$body,'From: info@jameswebdevelopment.com');
                
    // Print reply on screen
                
    echo '<p>Thank you, ' $contact ', for filling out our estimate form.  Someone will send you an email shortly with your estimate to the following email address:</p>' "\n";
                echo 
    '<p><a href="mailto:' $email '"><strong>$email</strong></a></p>';
            } else {
                
    // Print errors
                
    echo '<h2 id="error">Error</h2>' "\n";
                echo 
    "<p>The following errors have occurred:</p>\n";
                echo 
    '<ul class="errors">' "\n";
                foreach (
    $errors as $value) {
                    echo 
    '<li>' $value '</li>' "\n";
                }
                echo 
    "</ul>\n";
                
    // Display form as a Sticky Form
                
    echo '        <form method="post" action="estimate.php">' "\n";
                echo 
    '            <fieldset>' "\n";
                echo 
    '            <legend>Company Information</legend>' "\n";
                echo 
    '                <div class="formleft"><label for="contact">Contact Name (<span class="asterick">*</span>)</label><input type="text" class="text" name="contact" value="' $contact '" tabindex="1" /></div>' "\n";
                echo 
    '                <div class="formright"><label for="phone">Phone (<span class="asterick">*</span>)</label><input type="text" class="text" name="phone" value="' $phone '" tabindex="8" /></div>' "\n";
                echo 
    '                <div class="formleft"><label for="company">Company Name</label><input type="text" class="text" name="company" value="' $company '" tabindex="2" /></div>' "\n";
                echo 
    '                <div class="formright"><label for="email">Email (<span class="asterick">*</span>)</label><input type="text" class="text" name="email" value="' $email '" tabindex="9" /></div>' "\n";
                echo 
    '                <div class="formleft"><label for="address1">Address 1</label><input type="text" class="text" name="address1" value="' $address1 '" tabindex="3" /></div>' "\n";
                echo 
    '                <div class="formright"><label for="url">URL</label><input type="text" class="text" name="url" value="' $url '" tabindex="10" /></div>' "\n";
                echo 
    '                <div><label for="address2">Address 2</label><input type="text" class="text" name="address2" value="' $address2 '" tabindex="4" /></div>' "\n";
                echo 
    '                <div><label for="city">City (<span class="asterick">*</span>)</label><input type="text" class="text" name="city" value="' $city '" tabindex="5" /></div>' "\n";
                echo 
    '                <div><label for="state">State (<span class="asterick">*</span>)</label><input type="text" class="text" name="state" value="' $state '" tabindex="6" /></div>' "\n";
                echo 
    '                <div><label for="zip">Zipcode</label><input type="text" class="text" name="zip" value="' $zip '" tabindex="7" /></div>' "\n";
                echo 
    '            </fieldset>' "\n";
                echo 
    '            <fieldset>' "\n";
                echo 
    '            <legend>Description of Site (<span class="asterick">*</span>)</legend>' "\n";
                echo 
    '                <div><textarea name="description" cols="62" rows="15" tabindex="11">' $description '</textarea></div>' "\n";
                echo 
    '            </fieldset>' "\n";
                echo 
    '            <fieldset>' "\n";
                echo 
    '            <legend>Budget and Requirements</legend>' "\n";
                echo 
    '                <div>' "\n";
                echo 
    '                    <label for="services">What services do you require? (<span class="asterick">*</span>)</label>' "\n";
                echo 
    '                    <ul>' "\n";
                echo 
    '                        <li><input type="checkbox" name="services[]" value="New Website Development" tabindex="12" /> New Website Development</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="services[]" value="Website Re-design" tabindex="14" /> Website Re-design</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="services[]" value="Maintenance" tabindex="13" /> Maintenance</li>' "\n";
                echo 
    '                    </ul>' "\n";
                echo 
    '                </div>' "\n";
                echo 
    '                <div>' "\n";
                echo 
    '                    <label for="numberofpages">Approximate Number of Pages (<span class="asterick">*</span>)</label>' "\n";
                echo 
    '                    <ul>' "\n";
                echo 
    '                        <li><input type="radio" name="numberofpages" value="1-10 Pages" tabindex="15" /> 1-10 Pages</li>' "\n";
                echo 
    '                        <li><input type="radio" name="numberofpages" value="11-25 Pages" tabindex="16" /> 11-25 Pages</li>' "\n";
                echo 
    '                        <li><input type="radio" name="numberofpages" value="25-50 Pages" tabindex="17" /> 25-50 Pages</li>' "\n";
                echo 
    '                        <li><input type="radio" name="numberofpages" value="50-100 Pages" tabindex="18" /> 50-100 Pages</li>' "\n";
                echo 
    '                        <li><input type="radio" name="numberofpages" value="100+ Pages" tabindex="19" /> 100+ Pages</li>' "\n";
                echo 
    '                        <li><input type="radio" name="numberofpages" value="Not sure" tabindex="20" /> Not sure</li>' "\n";
                echo 
    '                    </ul>' "\n";
                echo 
    '                </div>' "\n";
                echo 
    '                <div>' "\n";
                echo 
    '                    <label for="budget">Website budget (<span class="asterick">*</span>)</label>' "\n";
                echo 
    '                    <ul>' "\n";
                echo 
    '                        <li><input type="radio" name="budget" value="0-1000" tabindex="21" /> $0-$1,000</li>' "\n";
                echo 
    '                        <li><input type="radio" name="budget" value="1000-3000" tabindex="22" /> $1,000-$3,000</li>' "\n";
                echo 
    '                        <li><input type="radio" name="budget" value="3000-5000" tabindex="23" /> $3,000-$5,000</li>' "\n";
                echo 
    '                        <li><input type="radio" name="budget" value="5000-7000" tabindex="24" /> $5,000-$7,000</li>' "\n";
                echo 
    '                        <li><input type="radio" name="budget" value="7000-10000" tabindex="25" /> $7,000-$10,000</li>' "\n";
                echo 
    '                        <li><input type="radio" name="budget" value="10000+" tabindex="26" /> $10,000+</li>' "\n";
                echo 
    '                    </ul>' "\n";
                echo 
    '                </div>' "\n";
                echo 
    '                <div>' "\n";
                echo 
    '                    <label for="when">When do you require our services? (<span class="asterick">*</span>)</label>' "\n";
                echo 
    '                    <ul>' "\n";
                echo 
    '                        <li><input type="radio" name="when" value="ASAP" tabindex="27" /> ASAP</li>' "\n";
                echo 
    '                        <li><input type="radio" name="when" value="In two weeks" tabindex="28" /> In two weeks</li>' "\n";
                echo 
    '                        <li><input type="radio" name="when" value="In one month" tabindex="29" /> In one month</li>' "\n";
                echo 
    '                        <li><input type="radio" name="when" value="In two months" tabindex="30" /> In two months</li>' "\n";
                echo 
    '                        <li><input type="radio" name="when" value="In three months" tabindex="31" /> In three months</li>' "\n";
                echo 
    '                        <li><input type="radio" name="when" value="In over three months" tabindex="32" /> In over three months</li>' "\n";
                echo 
    '                    </ul>' "\n";
                echo 
    '                </div>' "\n";
                echo 
    '                <div>' "\n";
                echo 
    '                    <label for="features">Requested website features (<span class="asterick">*</span>)</label>' "\n";
                echo 
    '                    <ul>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="Search Capabilities" tabindex="33" /> Search Capabilities</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="Blogs" tabindex="34" /> Blogs</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="Online Forums" tabindex="35" /> Online Forums</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="Message Boards" tabindex="36" /> Message Boards</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="Database Programming" tabindex="37" /> Database Programming</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="Domain(s) Registration" tabindex="38" /> Domain(s) Registration</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="PDF/Marketing Materials" tabindex="39" /> PDF/Marketing Materials</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="features[]" value="Not sure" tabindex="40" /> Not sure</li>' "\n";
                echo 
    '                    </ul>' "\n";
                echo 
    '                </div>' "\n";
                echo 
    '                <div>' "\n";
                echo 
    '                    <label for="howdidyouhear">How did you hear about us?</label>' "\n";
                echo 
    '                    <ul>' "\n";
                echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Google Search" tabindex="41" /> Google Search</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Other Search Engine" tabindex="42" /> Other Search Engine</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Link from another site" tabindex="43" /> Link from another site</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Recommendation" tabindex="44" /> Recommendation</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Email Solicitation" tabindex="45" /> Email Solicitation</li>' "\n";
                echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Snail Mail Solicitation" tabindex="46" /> Snail Mail Solicitation</li>' "\n";
                echo 
    '                    </ul>' "\n";
                echo 
    '                </div>' "\n";
                echo 
    '            </fieldset>' "\n";
                echo 
    '            <div><input class="submit" type="submit" name="submitted" value="Submit" /></div>' "\n";
                echo 
    '        </form>' "\n";
            }
        } else {
            
    // Display form to fill out
            
    echo '        <h2 id="estimate">Estimate</h2>' "\n";
            echo 
    '        <p>Please fill out the ESTIMATE FORM below and we will contact you with your estimate. You must fill out all sections labeled with an <span class="asterick">*</span>.</p>' "\n";
            echo 
    '        <form method="post" action="estimate.php">' "\n";
            echo 
    '            <fieldset>' "\n";
            echo 
    '            <legend>Company Information</legend>' "\n";
            echo 
    '                <div class="formleft"><label for="contact">Contact Name (<span class="asterick">*</span>)</label><input type="text" class="text" name="contact" tabindex="1" /></div>' "\n";
            echo 
    '                <div class="formright"><label for="phone">Phone (<span class="asterick">*</span>)</label><input type="text" class="text" name="phone" tabindex="8" /></div>' "\n";
            echo 
    '                <div class="formleft"><label for="company">Company Name</label><input type="text" class="text" name="company" tabindex="2" /></div>' "\n";
            echo 
    '                <div class="formright"><label for="email">Email (<span class="asterick">*</span>)</label><input type="text" class="text" name="email" tabindex="9" /></div>' "\n";
            echo 
    '                <div class="formleft"><label for="address1">Address 1</label><input type="text" class="text" name="address1" tabindex="3" /></div>' "\n";
            echo 
    '                <div class="formright"><label for="url">URL</label><input type="text" class="text" name="url" value="http://" tabindex="10" /></div>' "\n";
            echo 
    '                <div><label for="address2">Address 2</label><input type="text" class="text" name="address2" tabindex="4" /></div>' "\n";
            echo 
    '                <div><label for="city">City (<span class="asterick">*</span>)</label><input type="text" class="text" name="city" tabindex="5" /></div>' "\n";
            echo 
    '                <div><label for="state">State (<span class="asterick">*</span>)</label><input type="text" class="text" name="state" tabindex="6" /></div>' "\n";
            echo 
    '                <div><label for="zip">Zipcode</label><input type="text" class="text" name="zip" tabindex="7" /></div>' "\n";
            echo 
    '            </fieldset>' "\n";
            echo 
    '            <fieldset>' "\n";
            echo 
    '            <legend>Description of Site (<span class="asterick">*</span>)</legend>' "\n";
            echo 
    '                <div><textarea name="description" cols="62" rows="15" tabindex="11">Please provide us a brief description of what the site will be used for.</textarea></div>' "\n";
            echo 
    '            </fieldset>' "\n";
            echo 
    '            <fieldset>' "\n";
            echo 
    '            <legend>Budget and Requirements</legend>' "\n";
            echo 
    '                <div>' "\n";
            echo 
    '                    <label for="services">What services do you require? (<span class="asterick">*</span>)</label>' "\n";
            echo 
    '                    <ul>' "\n";
            echo 
    '                        <li><input type="checkbox" name="services[]" value="New Website Development" tabindex="12" /> New Website Development</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="services[]" value="Website Re-design" tabindex="14" /> Website Re-design</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="services[]" value="Maintenance" tabindex="13" /> Maintenance</li>' "\n";
            echo 
    '                    </ul>' "\n";
            echo 
    '                </div>' "\n";
            echo 
    '                <div>' "\n";
            echo 
    '                    <label for="numberofpages">Approximate Number of Pages (<span class="asterick">*</span>)</label>' "\n";
            echo 
    '                    <ul>' "\n";
            echo 
    '                        <li><input type="radio" name="numberofpages" value="1-10 Pages" tabindex="15" /> 1-10 Pages</li>' "\n";
            echo 
    '                        <li><input type="radio" name="numberofpages" value="11-25 Pages" tabindex="16" /> 11-25 Pages</li>' "\n";
            echo 
    '                        <li><input type="radio" name="numberofpages" value="25-50 Pages" tabindex="17" /> 25-50 Pages</li>' "\n";
            echo 
    '                        <li><input type="radio" name="numberofpages" value="50-100 Pages" tabindex="18" /> 50-100 Pages</li>' "\n";
            echo 
    '                        <li><input type="radio" name="numberofpages" value="100+ Pages" tabindex="19" /> 100+ Pages</li>' "\n";
            echo 
    '                        <li><input type="radio" name="numberofpages" value="Not sure" tabindex="20" /> Not sure</li>' "\n";
            echo 
    '                    </ul>' "\n";
            echo 
    '                </div>' "\n";
            echo 
    '                <div>' "\n";
            echo 
    '                    <label for="budget">Website budget (<span class="asterick">*</span>)</label>' "\n";
            echo 
    '                    <ul>' "\n";
            echo 
    '                        <li><input type="radio" name="budget" value="0-1000" tabindex="21" /> $0-$1,000</li>' "\n";
            echo 
    '                        <li><input type="radio" name="budget" value="1000-3000" tabindex="22" /> $1,000-$3,000</li>' "\n";
            echo 
    '                        <li><input type="radio" name="budget" value="3000-5000" tabindex="23" /> $3,000-$5,000</li>' "\n";
            echo 
    '                        <li><input type="radio" name="budget" value="5000-7000" tabindex="24" /> $5,000-$7,000</li>' "\n";
            echo 
    '                        <li><input type="radio" name="budget" value="7000-10000" tabindex="25" /> $7,000-$10,000</li>' "\n";
            echo 
    '                        <li><input type="radio" name="budget" value="10000+" tabindex="26" /> $10,000+</li>' "\n";
            echo 
    '                    </ul>' "\n";
            echo 
    '                </div>' "\n";
            echo 
    '                <div>' "\n";
            echo 
    '                    <label for="when">When do you require our services? (<span class="asterick">*</span>)</label>' "\n";
            echo 
    '                    <ul>' "\n";
            echo 
    '                        <li><input type="radio" name="when" value="ASAP" tabindex="27" /> ASAP</li>' "\n";
            echo 
    '                        <li><input type="radio" name="when" value="In two weeks" tabindex="28" /> In two weeks</li>' "\n";
            echo 
    '                        <li><input type="radio" name="when" value="In one month" tabindex="29" /> In one month</li>' "\n";
            echo 
    '                        <li><input type="radio" name="when" value="In two months" tabindex="30" /> In two months</li>' "\n";
            echo 
    '                        <li><input type="radio" name="when" value="In three months" tabindex="31" /> In three months</li>' "\n";
            echo 
    '                        <li><input type="radio" name="when" value="In over three months" tabindex="32" /> In over three months</li>' "\n";
            echo 
    '                    </ul>' "\n";
            echo 
    '                </div>' "\n";
            echo 
    '                <div>' "\n";
            echo 
    '                    <label for="features">Requested website features (<span class="asterick">*</span>)</label>' "\n";
            echo 
    '                    <ul>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="Search Capabilities" tabindex="33" /> Search Capabilities</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="Blogs" tabindex="34" /> Blogs</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="Online Forums" tabindex="35" /> Online Forums</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="Message Boards" tabindex="36" /> Message Boards</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="Database Programming" tabindex="37" /> Database Programming</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="Domain(s) Registration" tabindex="38" /> Domain(s) Registration</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="PDF/Marketing Materials" tabindex="39" /> PDF/Marketing Materials</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="features[]" value="Not sure" tabindex="40" /> Not sure</li>' "\n";
            echo 
    '                    </ul>' "\n";
            echo 
    '                </div>' "\n";
            echo 
    '                <div>' "\n";
            echo 
    '                    <label for="howdidyouhear">How did you hear about us?</label>' "\n";
            echo 
    '                    <ul>' "\n";
            echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Google Search" tabindex="41" /> Google Search</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Other Search Engine" tabindex="42" /> Other Search Engine</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Link from another site" tabindex="43" /> Link from another site</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Recommendation" tabindex="44" /> Recommendation</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Email Solicitation" tabindex="45" /> Email Solicitation</li>' "\n";
            echo 
    '                        <li><input type="checkbox" name="howdidyouhear[]" value="Snail Mail Solicitation" tabindex="46" /> Snail Mail Solicitation</li>' "\n";
            echo 
    '                    </ul>' "\n";
            echo 
    '                </div>' "\n";
            echo 
    '            </fieldset>' "\n";
            echo 
    '            <div><input class="submit" type="submit" name="submitted" value="Submit" /></div>' "\n";
            echo 
    '        </form>' "\n";
        }
    ?>
    Any advice would be appreciated!

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    South Florida
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to add proper Javascript verification to client end, also at the server side double check all the required fields are there before proceed

    JQuery form validation is a nice tool to validate your form, check out there web site
    http://docs.jquery.com/Plugins/Validation

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    The problem is, that text fields are always set when you submit the form, even if you didn't insert any data. Select fields are not, unless you select something.
    So you not only have to check if the $_POST variables exist, but if they exist, you'll have to check for valid input as well.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by lphy View Post
    You need to add proper Javascript verification to client end
    No you don't.

  5. #5
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using array_key_exists() instead of isset() for your declarations, and I think that should solve your problem.

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by SituationSoap View Post
    Try using array_key_exists() instead of isset() for your declarations, and I think that should solve your problem.
    Why do you think that?

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by lphy
    You need to add proper Javascript verification to client end
    js validation is a luxury not a necessity.

    Test empty after checking if the index exists.

  8. #8
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Why do you think that?

    Because isset() returns true on array values which are NULL, array_key_set() does not.


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
  •