【问题标题】:php code is displayed as plain text within form fieldsphp 代码在表单字段中显示为纯文本
【发布时间】:2013-04-23 04:34:51
【问题描述】:

我想实现一个联系表单,但浏览器将 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']?>

以纯文本形式在表单字段中显示。做错了什么?请帮忙。

【问题讨论】:

  • 你的 HTML 是 PHP 脚本的一部分吗?

标签: contact-form php


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      在某些服务器中,你不能使用&lt;?=,所以你必须使用这个:

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

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

      【讨论】:

      • 我得到了三个对我有帮助的相同答案,但你是最快的,RelevantUsername :)。我将 "=" 更改为 "
      【解决方案4】:

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

      更改&lt;?=

      <?php echo
      

      【讨论】:

        【解决方案5】:

        试试这个

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

        第二个

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

        第三个

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

        等等

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-03
          • 2017-07-21
          • 2015-05-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-04-29
          • 1970-01-01
          相关资源
          最近更新 更多