2011-06-07 113 views
1

好的頁面元素,所以我有這樣的:隱藏與PHP

<style type="text/css"> 
    <!-- 
    #frmFeedback { 
    display: <?php echo($myFormDisp); ?>; 
    } 
    --> 
</style> 

這:

//hide form 
$myFormDisp = "none"; 

所以...爲什麼不隱藏形式?

的完整代碼(修訂本):

<html> 

<head> 
<title>Feedback Form</title> 
<!-- Modified by: Student Name --> 
<!-- The page should accept user input in form values, then, after the form 
    is submitted, hide the form and reveal a confirmation message using 
    the data entered into the form elements. --> 


</head> 

<body> 
<h1 align="center">We Need You!</h1> 
<h2 align="center">Please provide us with your valuable feedback!</h2> 
<hr> 

<?php 
while (!(isset($myName) || isset($myAge) || isset($myFav) || isset($myComments))) 
    { 
    $myName = "anonymous"; 
    $myAge = "unspecified"; 
    $myFav = "unspecified"; 
    $myQuestion = "unspecified"; 
    } 

    $mySubmit = isset($_POST['btnSubmit']); 
?> 

<form name="frmFeedback" id="frmFeedback" action="sendFeedback.php" method="post" <?php if ($mySubmit == "Send Feedback!") { echo ' style="display: none"'; } ?>> 
Name: <input type="text" name="txtName"> 
<br> 
<br> 
Age: <select name="mnuAge"> 
    <option value="youth">Youth</option> 
    <option value="teen">Teen</option> 
    <option value="adult">Adult</option> 
    <option value="senior">Senior</option> 
    </select> 
<br> 
<br> 
What was your favorite page? 
<br> 
<input type="radio" name="radFav" value="ASP tutorial">ASP Tutorial 
<br> 
<input type="radio" name="radFav" value="JavaScript tutorial">JavaScript Tutorial 
<br> 
<input type="radio" name="radFav" value="PHP tutorial"> PHP Tutorial 
<br> 
<br> 
Which pages did you visit? 
<br> 
<input type="checkbox" name="chkView[]" value="ASP tutorial">ASP Tutorial 
<br> 
<input type="checkbox" name="chkView[]" value="JavaScript tutorial">JavaScript Tutorial 
<br> 
<input type="checkbox" name="chkView[]" value="PHP tutorial"> PHP Tutorial 
<br> 
<br> 
Do you have any additional scripting questions? 
<br> 
<textarea name="txaQuestions" wrap="soft" cols="50" rows="10"> 
</textarea> 
<br> 
<br> 
<input type="submit" name="btnSubmit" value="Send Feedback!"> 
</form> 
<?php 

//Once the form elements have been filled in, extract data from form and store in variables 
$myName = isset($_POST['txtName']); 
$myAge = isset($_POST['mnuAge']); 
$myFav = isset($_POST['rdFav']); 
$myQuestion = isset($_POST['txaQuestions']); 


if ($mySubmit == "Send Feedback!") 
    { 
    //hide form 
    //$myFormDisp = "none"; 

    //display message 
    print("<h3 align='center'>Thank you!!</h3>"); 
    print("Hello, ".$myName."!"); 
    print("Thank you very much for your feedback on our tutorial site."); 
    print("The ".$myAge." age group is one of our most critical market segments, so we really appreciate the time you took to fill out our form. "); 
    print("Active web visitors like yourself are what make these pages possible. "); 
    print("We are very glad you enjoyed the ".$myFav." page."); 

    if (isset($_POST['chkView'])) 
    { 
    print(", and hope that you found the other pages you viewed ("); 
    foreach($_POST['chkView'] as $myView) 
    { 
     print("".$myView.", "); 
    } 
    print("etc.) to be just as helpful."); 
    } 
    else 
    { 
    print(". The next time you visit we hope you have a chance to view our other tutorials also.</p>"); 
    } 

    print("<p>We will respond to your question: \"".$myQuestion."\" just as soon as we can</p>"); 

    print("<h3 align='center' Thanks for stopping by!</h3>"); 
    } 
else 
    { 
    //set form to display 
    //$myFormDisp = "block"; 
    } 

?> 

</body> 
</html> 
+0

也請發表您的HTML – 2011-06-07 21:13:19

+2

什麼的輸出你的腳本?你有沒有檢查過它實際上是'display:none;'? – alexn 2011-06-07 21:13:30

+2

結果HTML是什麼?你確實聲明'$ myFormDisp =「none」;'_before_輸出我所設想的CSS? – Wrikken 2011-06-07 21:14:26

回答

-1

你確定這是當你的CSS渲染設置?也許在css聲明之前嘗試一下<?php var_dump($myFormDisp); ?>

此外,在一個不相關的邊注,回聲不需要括號:

// This is better form for echo statements: 
<?php echo $myFormDisp; ?> 
+0

大家都是對的,這是隱藏表單的CSS問題。我解決了它,並沒有處理爲什麼要返回「1」值而不是插入的值。 – Anna 2011-06-07 21:56:36

-1

你可能需要:

<?php echo $myFormDisp; ?>

+0

他需要它在哪裏? – 2011-06-08 15:15:16

+0

@Phoenix而不是'<?php echo($ myFormDisp);' – joakimdahlstrom 2011-06-08 15:18:59