We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33337
    • 3,975 Posts
    Hi,

    I am using eform’s html validation for <textarea>, here is the code:
    <textarea class="required limited" name="Business_Overview" rows="15" cols="40" tabindex="27" eform="Business Overview:html:1">[+Business_Overview+]</textarea>
    

    Now, because I am using html, it converts new line to
    , if user simply put a normal text using return key its good, but if they put html formatted, e.g.
    My company do this
    <br/> and do this.. so on
    

    eform add one more
    , and result looks like:
    My company do this
    <br/><br/> and do this.. so on
    

    I don’t know if this is a bug or what, but I want to prevent this behavior, so any help would be much appreciated. smiley

    thanks and regards.
      Zaigham R - MODX Professional | Skype | Email | Twitter

      Digging the interwebs for #MODX gems and bringing it to you. modx.link
      • 30223
      • 1,010 Posts
      No, it’s not a bug, it’s a feature of sorts..

      The html data type has been there since eForm’s inception but, unlike most of eForm, has never evolved. Judging from the code I think the original idea behind the html data type was not so much to allow full blown html input but to be able to format text for an html email output. (although I may be wrong).

      Simply comment out line 292 in eform.inc.pcp (in version 1.4.2 that is)

      290         case "html":
      291             // convert \n to <br>
      292             //$value = str_replace("\n","<br />",$value); //comment out this line
      


      Be aware that there’s no checking of what kind of html tags are entered...
        • 33337
        • 3,975 Posts
        But I want to convert \n to
        , but if
        is already there it just skip it.

        OR

        when eform loads its values into fields, it converts
        into \n.

        possible?
          Zaigham R - MODX Professional | Skype | Email | Twitter

          Digging the interwebs for #MODX gems and bringing it to you. modx.link
          • 30223
          • 1,010 Posts
          OK, try this, replace line 292 with :

          $value = preg_replace('/(\n<br[ /]*?>|<br[ /]*?>\n|\n)/i','<br />',$value);


          This will replace any occurrence of a new-line and/or a new-line combined with a
          tag with a single
          tag.

          I’ve actually never used the html data type myself. I’m not sure what happens if the form fails for instance. Doe the
          tags get translated back into new-lines when the form is re-displayed or does the user suddenly see all his new-lines changed into tags? - I know I could find that out myself, but since you’re working on it... smiley