2013-04-22 102 views
0

我想實現一個聯繫表單,但瀏覽器將純文本顯示爲php代碼。下面是代碼:php代碼在表單域中顯示爲純文本

<div id="main-container"> 

    <div id="form-container"> 
    <h1>Fancy Contact Form</h1> 
    <h2>Drop us a line and we will get back to you</h2> 

    <form id="contact-form" name="contact-form" method="post" action="submit.php"> 
     <table width="100%" border="0" cellspacing="0" cellpadding="5"> 
     <tr> 
      <td width="15%"><label for="name">Name</label></td> 
      <td width="70%"><input type="text" class="validate[required,custom[onlyLetter]]" name="name" id="name" value="<?=$_SESSION['post']['name']?>" /></td> 
      <td width="15%" id="errOffset">&nbsp;</td> 
     </tr> 
     <tr> 
      <td><label for="email">Email</label></td> 
      <td><input type="text" class="validate[required,custom[email]]" name="email" id="email" value="<?=$_SESSION['post']['email']?>" /></td> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td><label for="subject">Subject</label></td> 
      <td><select name="subject" id="subject"> 
      <option value="" selected="selected"> - Choose -</option> 
      <option value="Question">Question</option> 
      <option value="Business proposal">Business proposal</option> 
      <option value="Advertisement">Advertising</option> 
      <option value="Complaint">Complaint</option> 
      </select>   </td> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td valign="top"><label for="message">Message</label></td> 
      <td><textarea name="message" id="message" class="validate[required]" cols="35" rows="5"><?=$_SESSION['post']['message']?></textarea></td> 
      <td valign="top">&nbsp;</td> 
     </tr> 
     <tr> 
      <td><label for="captcha"><?=$_SESSION['n1']?> + <?=$_SESSION['n2']?> =</label></td> 
      <td><input type="text" class="validate[required,custom[onlyNumber]]" name="captcha" id="captcha" /></td> 
      <td valign="top">&nbsp;</td> 
     </tr> 
     <tr> 
      <td valign="top">&nbsp;</td> 
      <td colspan="2"><input type="submit" name="button" id="button" value="Submit" /> 
      <input type="reset" name="button2" id="button2" value="Reset" /> 

      <?=$str?>   <img id="loading" src="img/ajax-load.gif" width="16" height="16" alt="loading" /></td> 
     </tr> 
     </table> 
     </form> 
     <?=$success?> 
    </div> 
    <div class="tutorial-info"> 
    This is a Tutorialzine demo. View the <a href="http://tutorialzine.com/2009/09/fancy-contact-form/">original tutorial</a>, or download the <a href="demo.zip">demo files</a>. </div> 

</div> 

所以,我得到這些

<?=$_SESSION['post']['name']?> 
<?=$_SESSION['post']['email']?> 
<?=$_SESSION['post']['message']?> 
表單字段中顯示

,因爲他們,爲純文本。什麼做錯了?請幫忙。

+0

是您的HTML腳本的一部分嗎? – Barmar 2013-04-22 20:30:26

回答

0

在某些服務器,則不能使用<?=,所以你必須使用此:

<?php echo $_SESSION['post']['name']; ?> 

或者乾脆讓在php.ini短標籤

+0

我得到了三個幫助我的相同答案,但您是最快的,RelevantUsername :)。我將「<?=」更改爲「<?php echo」,它工作正常。謝謝。 – user2170133 2013-04-22 21:07:10

0

短標籤在php.ini中可能被禁用你不應該無論如何使用它們

變化<?=

<?php echo 
0

試試這個

value="<?php echo $_SESSION['post']['name']; ?>" 

和第二

value="<?php echo $_SESSION['post']['email'] ; ?>" 

和第三

<?php echo $_SESSION['post']['message'] ; ?>