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.

Form Questions /

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

Form elements updated via AJAX

Go to End



Community Member, 1 Post

9 April 2009 at 10:28pm

Edited: 10/04/2009 12:05am

Hey guys,

Been struggling with the system for the past few days after someone in management decided to switch our microsites over to Silverstripe.

Naturally I headed straight for the tutorial section to get started on importing various forms into the system as pages. Since then I've been banging my head against the keyboard and swearing loudly. The tutorials are for very basic forms or rely too much on intrinsic knowledge of the system (this is no a system that's friendly to jump straight into). Code snippets are not verbose enough or have no context (hint: when writing tutorials always post all the final code (entire files) at the bottom, either inline or as downloads). There also seems to be some confusion about deprecated elements or missing documentation for various elements. And there seems to be almost no in-depth tutorials anywhere else on the wide web.

Ok on to the problems I'm having. I'm attempting to import a system that has seen the ravages and abuse of numerous feature creeps and as many 3 letter acronyms as can be shoved in as possible. So I'll break it down into the steps I'm fighting through.

Form elements updated via AJAX

I have 2 drop down fields. When you select from the first list, the second list becomes visible (problem 1) and is populated based on information in the first list (problem 2). The data that populates the second list is pulled from a remote server via a CURL call (that's fine) and can change at any moment so should only be called when a value in the first select box is selected.

I've experimented unsuccessfully with AjaxFormAction and various other actions without success. I'd rather take advantage of the object orientated system rather than hack it in the template source.

class ImportantForm_Controller extends Page_Controller {

    function newForm() {
        $fields = new FieldSet(
            new ListboxField('list1', 'List 1',  array('option 1', 'option 2', 'option 3')),
            new ListboxField('lsit2', 'List 2', array())

        $actions = new FieldSet(
            new FormAction('FormAction', 'Submit')

        return new Form($this, "Form", $fields, $actions);

    function FormAction($data, $form) {
        // Do something with the post