Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » HTMLEditorField not working as expected on frontend form

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1318 Views
  • Dr. J
    Avatar
    Community Member
    8 Posts

    HTMLEditorField not working as expected on frontend form Link to this post

    I am trying to create a frontend form containing an HTMLEditorField. I have set up the form fields as below

    $description = new HtmlEditorField('Description');
    $description->setRows(10);
    $fields = new FieldList(new TextField('Title', 'Job Title'),
                      new TextField('JobType','Type'),
                      new DateField('ClosingDate','Closing Date'),
                      new TextField('Reference'),
                      new TextField('ContactName','Contact'),
                      new EmailField('ContactEmail','Email'),
                      $description);


    and created the database table for the corresponding DataObject to include a corresponding HTMLText field

    class JobVacancy extends DataObject
    {
    static $db = array(
          'Title' => 'Text',
          'JobType' => 'Text',
          'ClosingDate' => 'Date',
          'Reference' => 'Text',
          'ContactName' => 'Text',
          'ContactEmail' => 'Text',
          'Description' => 'HTMLText'
    );
    }


    The form is rendered as expected in that it contains the description field as follows

    <div id="Description" class="field htmleditor">
       <label class="left" for="Form_CreateVacancyForm_Description">Description</label>
       <div class="middleColumn">
          <textarea name="Description" value="" class="htmleditor" id="Form_CreateVacancyForm_Description" rows="10" cols="10" tinymce="true" style="width: 97%; height: 160px"></textarea>
       </div>
    </div>


    and the entire form appears like the attached image.

    I am expecting this type of field to behave on my frontend form exactly the same way it does when I use this type of field on a tab in the CMS, consequently I have two problems:

    Problem 1: On submission, the record is created but the content of the HTMLText field is the same as the text entered in the form, that is plain text rather than the expected HTML markup. If I include markup directly to the field the record contains the markup I entered. Is this expected behaviour?

    Problem 2: There is no TinyMCE toolbar visible. Do I need to configure the page to display this? Is the absence of the TinyMCE toolbar related to Problem 1?

    I appreciate any assistance understanding and hopefully resolving this issue.

    Thanks

    Attached Files
  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: HTMLEditorField not working as expected on frontend form Link to this post

    Is the TinyMCE javascript loaded on the page or do you get a javascript error preventing it from loading?

  • Dr. J
    Avatar
    Community Member
    8 Posts

    Re: HTMLEditorField not working as expected on frontend form Link to this post

    Hi Willr

    I am not getting any js errors when the pages loads and Firebug indicates that the scripts declared at the end of the page

    </div>
    <script type="text/javascript" src="/tamsec.com.au/framework/thirdparty/tinymce/tiny_mce_gzip.php?m=1348579864&js=1&amp;plugins=contextmenu,table,emotions,paste,spellchecker&amp;themes=advanced&amp;diskcache=true&amp;src=false"></script>
    <script type="text/javascript" src="/tamsec.com.au/framework/thirdparty/jquery/jquery.js?m=1348579864"></script>
    <script type="text/javascript" src="/tamsec.com.au/framework/thirdparty/jquery-ui/jquery-ui.js?m=1348579860"></script>
    <script type="text/javascript" src="/tamsec.com.au/framework/javascript/DateField.js?m=1348579851"></script>
    <script type="text/javascript">//<![CDATA[
    if((typeof tinyMCE != 'undefined')) {
    var ssTinyMceConfig = {"friendly_name":"(Please set a friendly name for this config)","priority":0,"mode":"specific_textareas","editor_selector":"htmleditor","width":"100%","auto_resize":false,"theme":"advanced","theme_advanced_layout_manager":"SimpleLayout","theme_advanced_toolbar_location":"top","theme_advanced_toolbar_align":"left","theme_advanced_toolbar_parent":"right","blockquote_clear_tag":"p","table_inline_editing":true,"safari_warning":false,"relative_urls":true,"verify_html":true,"plugins":"contextmenu,table,emotions,paste,spellchecker","theme_advanced_buttons1":"bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,formatselect,separator,bullist,numlist,outdent,indent,blockquote,hr,charmap","theme_advanced_buttons2":"undo,redo,separator,cut,copy,paste,pastetext,pasteword,spellchecker,separator,advcode,search,replace,selectall,visualaid,separator,tablecontrols","theme_advanced_buttons3":""};
    }
    //]]></script></body>
    </html>

    are loading correctly.

    I am not explicitly setting configuration for the HTMLEditorField as I felt that the default would be sufficient to add the 'basics'. Could this be contributing to the behaviour I am seeing?

  • Willr
    Avatar
    Forum Moderator
    5497 Posts
  • Dr. J
    Avatar
    Community Member
    8 Posts

    Re: HTMLEditorField not working as expected on frontend form Link to this post

    ... but definitely related to this: HTMLEditor Field in frontend (SS3)

    (snap)

    1318 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.