2010-01-08 70 views
0

我有一个包含用户注册表单的弹出窗口。用户点击订阅后,我想要删除表单并显示一条感谢信息。所有这些都需要使用php来运行。表单提交后,使用PHP替换消息内容

以下是我到目前为止的内容,但弹出窗口并未保持不变,当再次单击订阅按钮时,它会显示表单验证错误,因为'subscribeSubmit'变量已设置。

那么,如何保持弹出窗口打开并用欢迎消息替换窗体?

请大家帮忙,谢谢!

<?php 
if(isset($_POST['subscribeSubmit'])){ 

unset($error); //errasing error variable 


//**************finding errors in form******************* 

if(strlen($_POST['Fname']) <= 0) {$error[] = "Your name is required.";} 

if(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$", stripslashes(trim($_POST['emailPopin'])))) {$error[] = "Your e-mail address is not valid.";} 

if(strlen($_POST['emailPopin']) <= 5) {$error[] = "You have to enter at least one e-mail to subscribe.";} 

if(strlen($_POST['industry']) <= 0) {$error[] = "Your industry is required.";} 

if(strlen($_POST['country']) <= 0) {$error[] = "Your country is required.";} 

if(strlen($_POST['zip']) <= 0) {$error[] = "Your zip is required.";} 

//************if there is an error********** 

if(sizeof($error) > 0) 
{ 
report_errors($error); 
subscribe_form();     
} 

//**********if there is no error, we can subscribe them****** 

else 
{ 

//**********Reduce First Name to 30 characters and replace special characters****** 

$name = substr($_POST['Fname'], 0, 30); 

//***** Replaces special characters ****** 
$name = special_letters($name); 


//**********write to data file****** 

//Left out on purpose 

//**********Display thank you message****** 

echo '<p>Thanks for signing up!<br/><a href="#" onClick="window.location.href=window.location.href">Click here to sign up friends.</a></p>'; 

} 

} 

else 

{ 

$Fname = $_POST["Fname"]; 
$email = $_POST["emailPopin"]; 
$leader = $_POST["radiobuttonTeamLeader"]; 
$industry = $_POST["industry"]; 
$country = $_POST["country"]; 
$zip = $_POST["zip"]; 


echo '<form action="" method="post" enctype="multipart/form-data" style="background:#efefef;">'; 

echo '<div style="text-align:left;background:#efefef;padding-bottom:4px;"><p style="line-height:20px; font-size:12px;">Fill in the form below to signup for our free daily newsletter. All fields are Necessary.(<span class="required">*</span>).</p><table id="popupSubscribe-form">'; 

echo '<tr><td class="label"><label for="name">First Name: <span class="required">*</span></label></td><td><input type="text" name="f_name" size="30" value=""></td></tr>'; 

echo '<tr><td class="label"><label for="email">Email: <span class="required">*</span></label></td><td><input type="text" size="30" id="emailPopin" value=""></td></tr>'; 

echo '<tr><td class="label"><label for="email">I Lead A Team: <span class="required">*</span></label></td>'; 

echo '<td><table><tr><td><input type="radio" value="yes" name="radiobuttonTeamLeader" style="width:15px;"><strong style="margin: 0 15px 0 5px;">Yes</strong></td>'; 

echo '<td><input type="radio" value="no" name="radiobuttonTeamLeader" style="width:15px;"><strong style="margin: 0 15px 0 5px;">No</strong></td></tr></table></td>'; 

echo '<tr><td class="label"><label for="industry">Industry: <span class="required">*</span></label></td><td><input type="text" name="industry" size="30" value=""></td></tr>'; 

echo '<tr><td class="label"><label for="country">Country <span class="required">*</span></label></td>'; 

echo '<td><select size="1" class="countryDropDown" name="country">'; 

echo '<option value="us" selected="selected">United States</option>'; 
echo '<option value="ca" >Canada</option>'; 

echo '</select></td></tr>'; 

echo '<tr><td class="label"><label for="email">Zip Code: <span class="required">*</span></label></td><td><input type="text" name="zip" size="30" value=""></td></tr>'; 

echo '<tr><td></td><td><input type="submit" id="subscribeSubmit" value="" name="subscribeSubmit"/></td></tr></table></div>'; 



echo '</form>'; 

} 

} 
+0

你说:'再次点击订阅按钮时,它会显示表单验证错误。所以出现有效的错误?或者你是说没有实际的错误,错误部分出现不正确? – 2010-01-08 21:33:38

+0

不,提交表单时没有有效的错误。 所以会发生什么。我填写表格,点击订阅,弹出消失,而不是显示谢谢你的消息。然后,我点击'点击此处订阅'按钮,弹出窗体并显示验证错误。 这是因为设置了isset($ _ POST ['subscribeSubmit'])而引起的。 我只是不知道如何解决它。 – Joe 2010-01-08 21:46:52

+0

这不是您需要更改的代码。我们需要看到'subscribe_form()'函数。它似乎是关闭你的弹出窗口。 – mattbasta 2010-01-10 23:25:00

回答

0

这是你要去的吗?

<?php 
if(isset($_POST['subscribeSubmit'])){ 

    unset($error); //errasing error variable 


    //**************finding errors in form******************* 

    if(strlen($_POST['Fname']) <= 0) {$error[] = "Your name is required.";} 

    if(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$", stripslashes(trim($_POST['emailPopin'])))) {$error[] = "Your e-mail address is not valid.";} 

    if(strlen($_POST['emailPopin']) <= 5) {$error[] = "You have to enter at least one e-mail to subscribe.";} 

    if(strlen($_POST['industry']) <= 0) {$error[] = "Your industry is required.";} 

    if(strlen($_POST['country']) <= 0) {$error[] = "Your country is required.";} 

    if(strlen($_POST['zip']) <= 0) {$error[] = "Your zip is required.";} 

    //************if there is an error********** 

    if(sizeof($error) > 0) 
    { 
     report_errors($error); 
     subscribe_form();     
    } 

    //**********if there is no error, we can subscribe them****** 

    else 
    { 

     //**********Reduce First Name to 30 characters and replace special characters****** 

     $name = substr($_POST['Fname'], 0, 30); 

     //***** Replaces special characters ****** 
     $name = special_letters($name); 


     //**********write to data file****** 

     //Left out on purpose 

     //**********Display thank you message****** 

     $thank_you_message = '<p>Thanks for signing up!<br/><a href="#" onClick="window.location.href=window.location.href">Click here to sign up friends.</a></p>'; 

    } 

    $Fname = $_POST["Fname"]; 
    $email = $_POST["emailPopin"]; 
    $leader = $_POST["radiobuttonTeamLeader"]; 
    $industry = $_POST["industry"]; 
    $country = $_POST["country"]; 
    $zip = $_POST["zip"]; 

} 

if(!empty($thank_you_message)){ 
    echo $thank_you_message; 
}else{ 

    echo '<form action="" method="post" enctype="multipart/form-data" style="background:#efefef;">'; 

    echo '<div style="text-align:left;background:#efefef;padding-bottom:4px;"><p style="line-height:20px; font-size:12px;">Fill in the form below to signup for our free daily newsletter. All fields are Necessary.(<span class="required">*</span>).</p><table id="popupSubscribe-form">'; 

    echo '<tr><td class="label"><label for="name">First Name: <span class="required">*</span></label></td><td><input type="text" name="f_name" size="30" value=""></td></tr>'; 

    echo '<tr><td class="label"><label for="email">Email: <span class="required">*</span></label></td><td><input type="text" size="30" id="emailPopin" value=""></td></tr>'; 

    echo '<tr><td class="label"><label for="email">I Lead A Team: <span class="required">*</span></label></td>'; 

    echo '<td><table><tr><td><input type="radio" value="yes" name="radiobuttonTeamLeader" style="width:15px;"><strong style="margin: 0 15px 0 5px;">Yes</strong></td>'; 

    echo '<td><input type="radio" value="no" name="radiobuttonTeamLeader" style="width:15px;"><strong style="margin: 0 15px 0 5px;">No</strong></td></tr></table></td>'; 

    echo '<tr><td class="label"><label for="industry">Industry: <span class="required">*</span></label></td><td><input type="text" name="industry" size="30" value=""></td></tr>'; 

    echo '<tr><td class="label"><label for="country">Country <span class="required">*</span></label></td>'; 

    echo '<td><select size="1" class="countryDropDown" name="country">'; 

    echo '<option value="us" selected="selected">United States</option>'; 
    echo '<option value="ca" >Canada</option>'; 

    echo '</select></td></tr>'; 

    echo '<tr><td class="label"><label for="email">Zip Code: <span class="required">*</span></label></td><td><input type="text" name="zip" size="30" value=""></td></tr>'; 

    echo '<tr><td></td><td><input type="submit" id="subscribeSubmit" value="" name="subscribeSubmit"/></td></tr></table></div>'; 

    echo '</form>'; 
} 
0

subscribe_form();与上面显示谢谢信息的else/echo之后的表单代码完全相同。

我试着留下评论,但显然没有足够的用户点,并且在发布问题时未登录。