php代码在表单字段中显示为纯文本

时间:2013-04-22 20:28:48

标签: contact-form 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']?>

在表单字段中显示为纯文本。怎么了?请帮助。

5 个答案:

答案 0 :(得分:2)

您是否支持在php.ini配置中启用short tags?可能就是这样。

答案 1 :(得分:1)

在PHP 5.4.0之前,速记语句受short_open_tag配置的影响。你可能想检查一下。请注意,建议不要使用这些简写语句,只是回显您的值。它产生更强大和可移植的代码。

http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

答案 2 :(得分:0)

在某些服务器中,您无法使用<?=,因此您必须使用此功能:

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

或者只是在php.ini中启用短标签

答案 3 :(得分:0)

PHP.ini中可能禁用了短标签,你不应该使用它们

更改<?=

<?php echo

答案 4 :(得分:0)

试试这个

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

和第二

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

和第三

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

等等