PHP code in form fields ?!?

Hi, could someone tell me why this code:


<form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
				<label for="name">Name: </label>
					<input type="text" name="name" value="<?php echo htmlentities($name) ?>
				<label for="email">Email: </label>
					<input type="text" name="email" value="<?php echo htmlentities($visitor_email) ?>">
				<label for="message">Message:</label> 
					<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>

Is displaying PHP code in the name, email and message areas of the form ? Is there a location that the PHP file be placed, I’ve tried a few methods nothing works.

It’s not your code… probably a server configuration issue.

Try adding this line above the form:

<?php phpinfo(); ?>

And show us the results…


<?php
if(isset($_POST['submit']))
{
	$name=$_POST['name'];
	$visitor_email=$_POST['email'];
	$user_message=$_POST['message'];
}
?>
<form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
                <label for="name">Name: </label>
                    <input type="text" name="name" value="<?php echo htmlentities(@$name) ?>">
                <label for="email">Email: </label>
                    <input type="text" name="email" value="<?php echo htmlentities(@$visitor_email) ?>">
                <label for="message">Message:</label>
                    <textarea name="message" rows=8 cols=30><?php echo htmlentities(@$user_message) ?></textarea>
					<input type="submit" name="submit">
					</form>


Note:::
Here ‘@’ suppresses the notices like,
at first time loading the form, this php variables are not initialized…

I tried both of your code before the form begins, same results :frowning:

You try only this code;
<?php phpinfo(); ?>

What’s the name of your file? Is it something.php? You may not have PHP installed on your server.

I disagree Transio :wink:

Each PHP statement must close with a semicolon.

And the HTML is wrong on the first input in the form , theres no closing speech mark or closing > to the input tag,

transio - I tried that code same thing. There is a PHP file. Mandes what are you referring too ?

Your code :rolleyes:

 
<DIV style="TEXT-ALIGN: left" dir=ltr><form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
<label for="name">Name: </label>
<input type="text" name="name" value="<?php echo htmlentities($name); ?>" >
<label for="email">Email: </label>
<input type="text" name="email" value="<?php echo htmlentities($visitor_email); ?>">
<label for="message">Message</label> 
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message); ?></textarea>
<DIV>

What I meant was ‘what part of the code’ I realize it was my code <g>
Edit: What is wrong ?

As I said earlier, your PHP statements werent followed by a semicolon ‘;’

And you had HTML errors (no closing tag or speech mark on the first input)

The code I posted in post #9 was CORRECTED so just copy and paste

Your code, mangles my page up. I copied the following code but that doesn’t work either:

<form method=“POST” name=“contact_form” action=“<?php echo htmlentities($_SERVER[‘PHP_SELF’]); ?>”>
<label for=“name”>Name: </label>
<input type=“text” name=“name” value=“<?php echo htmlentities($name); ?>” >
<label for=“email”>Email: </label>
<input type=“text” name=“email” value=“<?php echo htmlentities($visitor_email); ?>”>
<label for=“message”>Message</label>
<textarea name=“message” rows=8 cols=30><?php echo htmlentities($user_message); ?></textarea>

Then you have problems in other parts of your code too !!

Fixing these problems has had a chain effect on other errors.

The form was working, the problem was and still is that PHP code is showing up in the form input fields.

Fixing these problems has had a chain effect on other errors.

This is exactly why I asked the question, what is wrong with the form and what needs to be fixed.

What is the name of the file that contains form and php code?

html-contact-form.php
captcha_code_file.php
I hope this is what you’re asking ? :slight_smile:

Your first code was wrong, I fixed it for you, if that highlights other problems your going to have to post all the code so we can see where the other problems may lay.

Yes :slight_smile:

Some more questions:

  1. Where are you running this script? Local (on your own computer) or remote (a website) ?
  2. Do you have any other php scripts running on the same server that work ok?

Let’s first find out why the php commands aren’t parsed and executed. Even with the semicolumns missing, that would result in an error, not the entire php commands displayed in the html page.

agreed :wink:

But id be suprised if this is the only PHP in the entire script, so in that case all that code would be displaying too.

@SiberianHuskey

put this following code into a file called test.php, then run it, tell us the result.


<p>this is html</p>
<?php
echo 'this is php';
?>