Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I swear I had this working a couple hours ago but suddenly instead of only sending the form and saying "Thank you for filling out the form!" once the form is submitted, it does it once the page is loaded.

<?php
    if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['action']))) :
    endif; // form submitted

    if (isset($_POST['years'])) { $years = $_POST['years']; }
    if (isset($_POST['business'])) { $business = $_POST['business']; }
    if (isset($_POST['primary'])) { $primary = $_POST['primary']; }
    if (isset($_POST['improve'])) { $improve = $_POST['improve']; }
    if (isset($_POST['meaning'])) { $meaning = $_POST['meaning']; }
    if (isset($_POST['tagline'])) { $tagline = $_POST['tagline']; }
    if (isset($_POST['services'])) { $services = $_POST['services']; }
    if (isset($_POST['marketingrep'])) { $marketingrep = $_POST['marketingrep']; }
    if (isset($_POST['bestquality'])) { $bestquality = $_POST['bestquality']; }
    if (isset($_POST['qualityimprovement'])) { $qualityimprovement = $_POST['qualityimprovement']; }
    if (isset($_POST['mediateam'])) { $mediateam = $_POST['mediateam']; }
    if (isset($_POST['ifsoexperience'])) { $ifsoexperience = $_POST['ifsoexperience']; }
    if (isset($_POST['outside'])) { $outside = $_POST['outside']; }
    if (isset($_POST['succession'])) { $succession = $_POST['succession']; }
    if (isset($_POST['succession-interest'])) { $successioninterest = $_POST['succession-interest']; }
    if (isset($_POST['staff'])) { $staff = $_POST['staff']; }
    if (isset($_POST['licensed'])) { $licensed = $_POST['licensed']; }
    if (isset($_POST['vision'])) { $vision = $_POST['vision']; }
    if (isset($_POST['marketingplan'])) { $marketingplan = $_POST['marketingplan']; }
    if (isset($_POST['assist'])) { $assist = $_POST['assist']; }

    $formerrors = false;

   if ($years === '' ) :
       $err_years = '<div class="error">Please fill out this field.</div>';
       $formerrors = true;
   endif;

   if ($business === '' ) :
       $err_business = '<div class="error">Please fill out this field.</div>';
       $formerrors = true;
   endif;

   if (!($formerrors)) :
       $to = "[email protected]";
       $subject = "FIG Survey Landing Page Lead";
       $message = "How many years have you been with FIG? \r\n$years\r\n\r\nHow much business did you write in 2012? \r\n$business\r\n\r\nWhat is your primary source of marketing? \r\n$primary\r\n\r\nWhat could FIG improve on in fulfilling your marketing needs?\r\n$improve\r\n\r\nWhat does FIG mean to you? \r\n$meaning\r\n\r\nWhat is FIG's tagline? \r\n$tagline\r\n\r\nWhat services does FIG do for you? \r\n$services\r\n\r\nWho is your marketing rep? \r\n$marketingrep\r\n\r\nWhat is their best quality? \r\n$bestquality\r\n\r\nWhat's the quality they most need to improve on? \r\n$qualityimprovement\r\n\r\nHave you ever spoken with our All Points Media Team? \r\n$mediateam\r\n\r\nIf so, what was your experience? \r\n$ifsoexperience\r\n\r\nWhat do you do outside of work? \r\n$outside\r\n\r\nDo you have a succession plan? \r\n$succession\r\n\r\nAre you interested in implementing one? \r\n$successioninterest\r\n\r\nDo you have a staff? If so how many? Please list roles in office: \r\n$staff\r\n\r\nAre you series 6, 7 or 65 licensed? Please list which one(s). \r\n$licensed\r\n\r\nWhat is your vision? \r\n$vision\r\n\r\nDo you have a marketing plan? \r\n$marketingplan\r\n\r\nWhat else could FIG be doing to assist you with your business? \r\n$assist\r\n\r\n";

       if (mail($to, $subject, $message)) :
        $msg = "Thanks for filling out the survey!";
       else:
           $msg = "Problem sending the message";
        endif;     

   endif;
?>

Any ideas? Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Why do you have endif; right after the opening conditional to check if this is incoming POST? My guess is that this should be moved all the way to the end of this code snippet and have all other conditionals nested inside of it.

I would strongly recommend use of the more widely used bracket notation to make such mistakes more readily visible (most code editors will do a code job of highlighting matching brackets).

You should probably also be defaulting the values for you various form variables to '' or whatever as when you starting checking things like

if ($years === '' )

if $years hasn't been defined because the value was not posted, you will get a notice about undefined variable.

share|improve this answer
 
Wow, I had the same thought but that is the code I got directly from a tutorial I watched...Thanks it worked! –  user2415116 Jul 16 '13 at 20:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.