We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37111 ☆ A M B ☆
    • 31 Posts
    Hey guys,
    I'm working on a website, where trainees can add their profile to find a job. Therefore I have added a WYSIWYG (ckeditor) to allow the input of an HTML-curriculum vitae.
    Everything works fine - but after the form-submission, the linebreaks and all html-tags are gone in the curriculum.
    I think they were stripped out, before they get saved as part of the "extended user fields"-JSON.

    Has anyone an idea how to get that done?
    Thanks and greetings from Germany
    Jens

    This question has been answered by vamporio. See the first response.

      • 36572
      • 20 Posts
      Did you try to use html entities before saving the data?

      Do not know if it will work but you can give a try.
        Developer @ Sterc bureau voor internet & marketing
        • 37111 ☆ A M B ☆
        • 31 Posts
        Quote from: sterce-friso at Feb 26, 2013, 09:23 AM
        Did you try to use html entities before saving the data?

        Do not know if it will work but you can give a try.

        Thanks for your idea, but I could handle the problem with another way.
        I will write a small tutorial in a post below ;-)
        • discuss.answer
          • 37111 ☆ A M B ☆
          • 31 Posts
          ** update 2.0 - I found the cause why it was not working correctly by using the default UpdateProfile-Settings **
          The Problem was, that Login.UpdateProfile and Login.Register both use FormIt for validating the user-inputs.
          And in FormIt all inputs are stripped by default. So you have to enable the "allowTags" for every field in
          validation which should contain html.

          http://rtfm.modx.com/display/ADDON/FormIt.Validators

          =================================================================================
          stripTags Strip all tags from the field. Note that this is on by default.
          allowTags Allow tags in the field.
          =================================================================================

          For example:
          You want to enable HTML-content for the fields "comment" and "myExtendedField", you have to do it like so:

          FormIt:

          [[!FormIt?
             &validate=`comment:allowTags,myExtendedField:allowTags`
          ]]


          UpdateProfile
          [[!UpdateProfile?
             &validate=`comment:allowTags,myExtendedField:allowTags`
          ]]



          Register

          [[!Register?
             &validate=`comment:allowTags,myExtendedField:allowTags`
          ]]


          After doing this, both fields gets saved corretly with all the HTML inside. Thats the best way to do it. You can
          also use my first way, over the hooks.. But this is unnecessary overhead, because the system has to save twice.
          -----------------------------------------------------------------------------------------------------------------

          Tutorial - How to do it ---- the "Hook-Way":

          ** update 1.0 - added solution to make it also work as postHook for the Login.Register-Snippet **

          First of all, you have to add a post-hook to the UpdateProfile-Snippet:
          [[!UpdateProfile? &postHooks=`updateHTMLFields`]]

          Then you have to create a Snippet "updateHTMLFields" with the following content:
          // check if uid is set in the post
          if(isset($_POST['uid']) && !empty($_POST['uid'])){
           // true: get the user-profile from the Updates-Snippet
           $profile = $hook->getValue('updateprofile.profile');
          }else{
           // false: get the user-profile from the Register-Snippet
           $profile = $hook->getValue('register.profile');
          }
          
          // get the extended fields from the profile
          $extended = $profile->get('extended');
          
          // example 1 - extended field
          // if your special extended-html-field existed in the update-form
          if(isset($_POST['myExtendedHTMLField'])){
              // then replace the actual (stripped) value with the correct one
              $extended['myExtendedHTMLField'] = $_POST['myExtendedHTMLField'];
          }
          
          // example 2 - another extended field to work with
          if(isset($_POST['myExtendedHTMLField_2'])){
              $extended['myExtendedHTMLField_2'] = $_POST['myExtendedHTMLField_2'];
          }
          
          // example 3 - standard-field (like adress, comment..)
          // if your special-html-field is no extended field
          if(isset($_POST['comment']) ){
              // you can replace it like so
              $profile->set('comment', $_POST['comment']);
          }
          
          // set all changed extended fields to the profile
          $profile->set('extended', $extended);
          // save all changes to the profile
          $profile->save();


          I hope this is useful for anybody with the same problem ;-)

          Greetings from Germany
          Jens [ed. note: vamporio last edited this post 13 years, 7 months ago.]