1

我发誓我在几个小时前就已经完成了这项工作,但突然间不再只是发送表格并说“谢谢您填写表格!” 一旦表单被提交,它会在页面加载后执行。

<?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 = "fakeemail@gmail.com";
       $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;
?>

有任何想法吗?谢谢!

4

1 回答 1

1

为什么您endif;在打开条件后立即检查这是否是传入的 POST?我的猜测是,这应该一直移动到此代码片段的末尾,并将所有其他条件嵌套在其中。

我强烈建议使用更广泛使用的括号表示法,以使此类错误更容易被发现(大多数代码编辑器都会执行突出显示匹配括号的代码工作)。

您可能还应该将各种表单变量的值默认为''或开始检查之类的东西

if ($years === '' )

如果$years由于未发布值而尚未定义,您将收到有关未定义变量的通知。

于 2013-07-16T20:53:33.117 回答