user2170133
user2170133

Reputation: 79

php code is displayed as plain text within form fields

I want to implement a contact form, but browser displays php code as plain text. Here is the code:

<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>

So, I get these

<?=$_SESSION['post']['name']?>
<?=$_SESSION['post']['email']?>
<?=$_SESSION['post']['message']?>

displayed inside form fields as they are, as plain text. What am doing wrong? Pls, help.

Upvotes: 0

Views: 440

Answers (5)

Nick Rolando
Nick Rolando

Reputation: 26177

Before PHP 5.4.0, shorthand statements are affected by short_open_tag configuration. You may want to check that. Note, it is not recommended to use these shorthand statements and to just echo your values. It produces more robust and portable code.

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

Upvotes: 1

echo_Me
echo_Me

Reputation: 37233

try this

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

and second

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

and third

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

and so on

Upvotes: 0

Jim Maitland
Jim Maitland

Reputation: 16

Short tags are probably disabled in PHP.ini and you should not use them anyway

Change<?= To

<?php echo

Upvotes: 0

RelevantUsername
RelevantUsername

Reputation: 1340

In some server, you can't use <?=, so you must use this :

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

Or simply enable short tags in php.ini

Upvotes: 0

Deleteman
Deleteman

Reputation: 8700

Do you have support for short tags enabled on your php.ini configuration? That might be it.

Upvotes: 2

Related Questions