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.

General Questions

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

Inserting Drop Down Selector via HTML


Reply

3 Posts   388 Views

Avatar
goodness

8 June 2013 at 3:27am (Last edited: 8 June 2013 3:27am), Community Member, 38 Posts

I am attempting to insert a drop down selector on a page within the CMS.
I've tried using the HTML Source Editor on the page but with I click "Update" it strips out my code.

My plan was to use this as a way to navigate to anchor tags within an FAQ page without listing out all of the questions at the top of the page as links.

I was using code like this:

<select name="selectionField">
<option value="Question 1" ><a href="#quest1"Question One</a></option>
<option value="Question 2" ><a href="#quest2">Question Two</a></option>
<option value="Question 3" ><a href="#quest3">Question Three</a></option>
</select>

Any help will be greatly appreciated.

Thanks!

Avatar
goodness

12 June 2013 at 3:10am Community Member, 38 Posts

I'm still trying to figure out how to get this on a page without the system stripping out the code.

This code works in a stand-alone webpage:

<form>
<select name="faqForm" ONCHANGE="location = this.options[this.selectedIndex].value;">
<option value="#">Select Your Question</option>
<option value="#quest1">Question One</option>
<option value="#quest2">Question Two</option>
<option value="#quest3">Question Three</option>
<option value="#quest4">Question Four</option>
<option value="#quest5">Question Five</option>
</select>
</form>

However, when I go into the HTML Source Editor (within the content area for the page) and type the above code in - the system strips it out as soon as I click Update. It converts it to this:

<p>Select Your QuestionQuestion OneQuestion TwoQuestion ThreeQuestion FourQuestion Five</p>

Is there a trick to getting the system to leave my code as is?

Anyone?

Avatar
Devlin

12 June 2013 at 3:49am Community Member, 215 Posts

What you're looking for is "valid_elements" and "extended_valid_elements", options of tinyMCE.

http://www.tinymce.com/wiki.php/Configuration:valid_elements
http://www.tinymce.com/wiki.php/Configuration:extended_valid_elements

You can set this options with:

HtmlEditorConfig::get('cms')->setOptions();

But I have to tell you: what you want to do is actually a bad idea. Especially the additional "form" tags in your code.

You could simply write a method in your page class, which seeks your anchor tags in $this->Content() and return them as a DropdownField for the template.