Submit Your Article Forum Rules

Results 1 to 10 of 10

Thread: Truncated text box - PHP

  1. #1
    Member
    Join Date
    Nov 2006
    Posts
    79

    Truncated text box - PHP

    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

  2. #2
    WebProWorld MVP wige's Avatar
    Join Date
    Jun 2006
    Posts
    3,138

    Re: Truncated text box - PHP

    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;
    The best way to learn anything, is to question everything.
    WigeDev - Freelance web and software development

  3. #3
    Member
    Join Date
    Nov 2006
    Posts
    79

    Re: Truncated text box - PHP

    Thanks for responding Wige but no joy. Not sure what is going on here.

    DaK

  4. #4
    WebProWorld MVP wige's Avatar
    Join Date
    Jun 2006
    Posts
    3,138

    Re: Truncated text box - PHP

    Can you post what the tag looks like when you view source on the rendered page?
    The best way to learn anything, is to question everything.
    WigeDev - Freelance web and software development

  5. #5
    Member
    Join Date
    Nov 2006
    Posts
    79

    Re: Truncated text box - PHP

    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

  6. #6
    WebProWorld MVP wige's Avatar
    Join Date
    Jun 2006
    Posts
    3,138

    Re: Truncated text box - PHP

    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.
    The best way to learn anything, is to question everything.
    WigeDev - Freelance web and software development

  7. #7
    Member
    Join Date
    Nov 2006
    Posts
    79

    Re: Truncated text box - PHP

    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

  8. #8
    WebProWorld MVP wige's Avatar
    Join Date
    Jun 2006
    Posts
    3,138

    Re: Truncated text box - PHP

    PHP Code:
    $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.
    The best way to learn anything, is to question everything.
    WigeDev - Freelance web and software development

  9. #9
    Member
    Join Date
    Nov 2006
    Posts
    79

    Re: Truncated text box - PHP

    Bingo!

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

    DaK

  10. #10
    Junior Member
    Join Date
    Dec 2007
    Posts
    4

    Re: Truncated text box - PHP

    Congrats for you success.
    Another variant is to use Css or dhtml for your needs.

Similar Threads

  1. is google ok with sites that has text link color same as regular text
    By deafsinger in forum Google Discussion Forum
    Replies: 9
    Last Post: 10-10-2008, 04:14 AM
  2. Cookie Values getting truncated
    By MHenscheid in forum Web Programming Discussion Forum
    Replies: 0
    Last Post: 01-14-2005, 01:10 PM
  3. Replies: 26
    Last Post: 07-09-2004, 10:44 PM
  4. Replies: 5
    Last Post: 07-04-2004, 12:33 AM
  5. inserting text into text area button
    By icb01co2 in forum Web Programming Discussion Forum
    Replies: 1
    Last Post: 02-13-2004, 05:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •