ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

fitting <textbox> input into DDS fixed length fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • fitting <textbox> input into DDS fixed length fields

    I have an HTML textboox (say 60 columns * 5 lines = 300 characters) that I want to write to 5 X 60-character fields in a set of 5 X 60 character fileds.

    My first inclination was to substring 60 character increments of the returned text.

    Ah, but this won't work because textboxes do some funky word wrapping and HTML sucks out extra spaces. Then I started to figure out last full word and add back extra spaces but that is getting messy.

    Anyone have a better HTML/PHP approach too this?

    (And no Bryce I cannot redesign corporate the A/R system to accomodate this requirement.)

  • #2
    Re: fitting &lt;textbox&gt; input into DDS fixed length fields

    Spaces in a text string when passed via a form post will have &#37;20 for the spaces and regular ascii text for the characters. Can't you move the string into a array that is 300 and do your search for %20 or an empty space that way? Check if the 60th element is a blank, if not back up one in the array and check again, and again until you get to the last space. Then grab that group and plop it into your screen fields.

    Question: If you wrap words in the text box do you still get the 300 characters no matter what? Do the 300 characters include whitespace?

    I'm positive this can be done fairly easily. You don't need to redesign, just out think the html guys
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

    Comment


    • #3
      Re: fitting &lt;textbox&gt; input into DDS fixed length fields

      If you don't need the user to be able to format text,
      then, just output your formatted text to a scrollable div with
      <pre>
      Preformatted text.
      It preserves both spaces
      and line breaks.
      </pre>

      Otherwise, you need to use rich text Advanced textboxes

      Search Google: rich text textboxes

      Comment


      • #4
        Re: fitting &lt;textbox&gt; input into DDS fixed length fields

        We've had similar problems here. The simple answer is no, there is no nice way of doing this. Frankly it's horrible! Marc's suggestion of looking for rich text boxes is ok if you want to allow the user to format the text as bold or italic but there is no JavaScript component that converts from a multiline textbox to an old AS400 database format with 5*60 characters. It seems to me a very AS400 thing to have the comment in separate fields like this because of the way 5250 screens are coded. I've certainly not come across such shenanigans elsewhere and hence you wont find much help searching for rich textboxes.

        I think you have two choices. The easiest is to break it up on the server and if they blow the limit of rows/chars for the file send an error message back to the client. If they don't like that (and sadly our client didn't) then you're in for a lot of pain writing a client script to limit the chars/rows, insert line feed automatically etc.

        Things to be aware of:
        They can insert a line break by pressing enter. In firefox this inserts one carriage return character but in IE it inserts a carriage return and linefeed. This means the total number of characters will be wrong in IE. You need to search for the hex value for linefeed characters or space, not %20.

        The cols width you can give a text area is an "estimation" at best. It won't wrap at 60 chars if that involves breaking up a word and you don't get that line break sent back to the server anyway. You'll have to insert a linefeed yourself automatically in a script.
        Ben

        Comment


        • #5
          Re: fitting &lt;textbox&gt; input into DDS fixed length fields

          I haven't tried it yet, but I think I could suck out some of the special and html characters, then use then wordwrap() and str_split() functions to determine how many lines would result. If not too many lines, I could convert resulting string to an array and break each array element into a DDS field. Did I forget anything?
          PHP Code:

          PHP wordwrap function.

          <?php
          $text 
          "The quick brown fox jumped over the lazy dog.";
          $newtext wordwrap($text20"@@");
          echo 
          $newtext;
          ?> 

          The above example will output:

          The quick brown fox@@
          jumped over the lazy@@
          dog.
          Here are some good discussions of the issue...


          Discussion and examples on using PHP to wrap to a specified number of characters or number of lines. Also examples of splitting text into columns for presentation in HTML.

          Comment


          • #6
            Re: fitting &lt;textbox&gt; input into DDS fixed length fields

            What if they entered the text in the multiline textarea with line breaks?

            For example if they entered

            The quick brown
            fox jumped over the lazy dog.

            To split it the way you suggest you would have to strip out that carriage return character. Otherwise you might be storing the following in the database.

            The quick brown@@ fox@@
            jumped over the lazy@@
            dog.

            Which would then be re-displayed like this.

            The quick brown
            fox
            jumped over the lazy
            dog.

            It depends if the user wants any control over the formatting. Ours did because they were pasting in comments with a label and value. E.G.

            Name: Ben
            Country: UK
            Age: 26

            Simply stripping the carriage returns they wanted would result in a comment like this.

            Name: Ben Country:
            UK Age:26

            It's not as simple as you might first think. I guess it depends on what the user wants as to how hard it is. Ours wanted the world...
            Ben

            Comment


            • #7
              Re: fitting &lt;textbox&gt; input into DDS fixed length fields

              Here is a second attempt.

              PHP Code:
              fnPreparetextArea($textAreaString648); 

              function 
              fnPreparetextArea($textAreaString,$maxlineLength,$maxLines

                
              // replace "white spaces" with a single space 
                
              $textAreaString preg_replace('/\s+/'' '$textAreaString) ;     
                
              // break string into chunks of of $maxlineLength or less with wordwrap() 
                
              $textAreaString wordwrap($textAreaString$maxlineLength'@!'TRUE) ;             
                
              //count number of lines
                
              $countLines substr_count $textAreaString"@!" );     
                
              // test to see if we have exceeded maximum number of lines  
                
              if($countLines>$maxLines
                { 
                  echo 
              "Sorry your string is too long."
                } 
                else 
                { 
                  
              $count 0
                  
              // if OK, then break lines apart & write to file 
                  
              $lines explode("@!"$textAreaString); 
                  foreach (
              $lines as $oneLine)  
                  { 
                     echo 
              $count " " $oneLine "<br>"
                     
              // SQL stuff here - write one line to file 
                     
              $count++; 
                  } 
                } 

              Comment

              Working...
              X