Jump to content

[SOLVED] Question about Form Fields


JSHINER

Recommended Posts

$var = "The length is 5' x 2" and blah blah";

 

<input type="text" name="textBox" value="<?php echo $var; ?>">

 

In the <input> this cuts off at the ' if I do value='' and the " if I do value ="" and at either if I just do value=

 

How do I get around this?

Link to comment
https://forums.phpfreaks.com/topic/128403-solved-question-about-form-fields/
Share on other sites

$var = "The length is 5' x 2" and blah blah";

 

<input type="text" name="textBox" value="<?php echo $var; ?>">

 

In the <input> this cuts off at the ' if I do value='' and the " if I do value ="" and at either if I just do value=

 

How do I get around this?

 

You need to escape the quote that would otherwise cause the string to terminate:

$var = "The length is 5' x 2\" and blah blah blah";

It is the input field, it's not actually a PHP related question - it's straight HTML.

 

Don't you just LOVE HTML? :)

 

By the way, here is a quick fix, use the HTML code for the double quotation:

$var = "The length is 5' x 2&#34; and blah blah";

It will output correctly for you and show up right, just a pain to work with.

 

EDIT:

" might work in place of &#34; and a bit easier to use.

To put characters that have meaning in HTML into form field value parameters, you need to convert the special characters to HTML entities so that they are not operated on by the browser when it renders the page - http://us3.php.net/htmlentities

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.