PDA

View Full Version : Truncated text box - PHP



dak888
11-29-2007, 11:19 AM
Hello everyone,

Having a problem with one of my text boxes and the displayed value being truncated.

<input name="Comments" id="Comments" type="text" value="<?php echo htmlspecialchars($row_orderComments['PPassValue']); ?>" />

Text is displayed right up to the first space character and then nothing...

I have several other text boxes on the same page with no issues so I'm a bit perplexed as to why this one is being truncated.

I added the htmlspecialchars after doing some reading but no joy. When I view the source of the page, the entire value is written correctly in the value= field but its not displaying in the text box. There are no size or max char limitations. I've tested it with both fields that may have special characters and one's without any special character but still nothing.

I've also created it so it's not in a form element and it displays just fine. It's just when it's in a text box.

*scratches head*

Any help is appreciated.

Thanks,

DaK

wige
11-29-2007, 01:05 PM
Try this: <input name="Comments" id="Comments" type="text" value="<?=htmlspecialchars($row_orderComments['PPassValue'])?>" /> This will remove formatting issues that may result from any PHP syntax. Also, make absolutely sure that the first quotation mark is in the position shown in your sample, and that the htmlspecialchars function is not replacing spaces with &nbsp;

dak888
11-29-2007, 04:47 PM
Thanks for responding Wige but no joy. Not sure what is going on here.

DaK

wige
11-29-2007, 05:26 PM
Can you post what the tag looks like when you view source on the rendered page?

dak888
11-30-2007, 10:43 AM
Sure,

<td><input name="Comments" id="Comments" type="text" value="ph-LCM
please cut pole 5ft and two pieces of 86 , 3 pieces total." /></td>

In the text box on the page itself, you only see "ph-LCM".

Thanks,

DaK

wige
11-30-2007, 11:33 AM
My theory is that a newline is being added somehow, possibly by the special characters function (changing a br to a newline?) or by whatever is putting the value into/getting the value from the database. Text fields do not display anything after a \n or \r, unlike text areas.

dak888
11-30-2007, 11:36 AM
That is very possible and would probably explain why the other text boxes work fine since there is no possibility of there being line breaks.

Is there a quick way I can sanatize for the line breaks? I'm not that good with regular expressions.

Thanks,

DaK

wige
11-30-2007, 11:48 AM
$row_orderComments['PPassValue'] = ereg_replace("\n", '', $row_orderComments['PPassValue']);
$row_orderComments['PPassValue'] = ereg_replace("\r", '', $row_orderComments['PPassValue']);

This will remove both \n and \r. Some systems do line returns with both characters (\r\n) so you need to sanitize for both.

dak888
11-30-2007, 12:29 PM
Bingo!

Works like a charm. Thanks for bailing me out Wige!

DaK

canzoni32
12-06-2007, 04:18 AM
Congrats for you success.
Another variant is to use Css or dhtml for your needs.