tags:

views:

174

answers:

1

Hello,

There seems to be a problem, where i can't display the complete value in a html form text input box.

$title = "Stacey's Mom";

This is the html code I used to show the value.

Title:

This returns the value in textbox as "Stacey". Samething happens when "," or "'" or "/" occurs in the text.

How can I show the entire text in the textbox.

Help would be much appreciated.

A: 

The problem is that when you have an apostrophe, the HTML ends up like this:

value = 'Stacey's Mom'

So that apostrophe closes the value. What you need to do is use the htmlspecialchars function when displaying anything from user input.

I'd also suggest using single quotes for outputting HTML since it can make the code a bit cleaner (you don't need to escape double quotes). Something like this:

echo 'Title: <input type="text" name="title' . $counter . '" value="' . htmlspecialchars($title) . '" />';
DisgruntledGoat