Jump to:

23472 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » creating button tags and CMS issue

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 942 Views
  • Crossbound
    Avatar
    Community Member
    14 Posts

    creating button tags and CMS issue Link to this post

    I have been trying to use <button> instead of <input> tags for form submissions, but also wanted to be able to add a <span> tag within the <button> tag to have more options with CSS styling
    After searching through code in the Sapphire framework I found that the tags are build in FormField.php starting on line 495. I changed the code on line 502 to look as follows

    if($content || $tag != 'input') {
    if($tag == 'button'){
    return "<$tag$preparedAttributes><span>$content</span></$tag>";
    } else {
    return "<$tag$preparedAttributes>$content</$tag>";
    }
    }

    So everything seemed to work just right, until I logged into the CMS and discovered that now the buttons for "unpublish", "save". "save and publish", etc. are no longer working.
    I assume that Javascript (I don't know very much about Javascript and AJAX) is no longer able to get to the content of the button because of the <span> tag. If my assumption is correct, is there a possibility to check within the PHP code if these buttons are used in the CMS and not the front end, so that the <span> tags would not be written out?

    Thanks so much

  • 3dgoo
    Avatar
    Community Member
    133 Posts

    Re: creating button tags and CMS issue Link to this post

    I would advise against modifying Sapphire or CMS for the intention of styling buttons. It's bound to break the cms.

    Alternatives are:
    styling the buttons without the span
    building the forms yourself in the template, then you can have what ever crazy tags you want
    using jquery to add the spans to the button tags on document load

  • Crossbound
    Avatar
    Community Member
    14 Posts

    Re: creating button tags and CMS issue Link to this post

    Ampedup, thanks for the reply.

    I don't like changing anything in Sapphire, and changed everything back to the way it was. Using the <input> submit works well, just limits the way I would have liked to style the buttons. I'm using the userforms modul, which adds an other layer of code that I really rather not deal with. I had hoped for a quick and simple solution, but can deal with what I got.

    Just FYI: it was not the <span> tag that caused the problem in the backend, but the <button> tag itself. I tried without the <span> tag and saving still didn't work, until going back to <input>

    942 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.