Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

creating button tags and CMS issue


Go to End


3 Posts   1747 Views

Avatar
Crossbound

Community Member, 14 Posts

3 May 2010 at 4:29pm

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

Avatar
3dgoo

Community Member, 135 Posts

5 May 2010 at 1:32pm

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

Avatar
Crossbound

Community Member, 14 Posts

5 May 2010 at 2:30pm

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>