Jump to:

23355 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Form Submit onChange without submit Button

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: 419 Views
  • Andre
    Avatar
    Community Member
    126 Posts

    Form Submit onChange without submit Button Link to this post

    Hi,

    I have written a simple Dropdown Form with Submit Button, to change/select the page language.

    Here is the code:

    <?php

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    class BootstrapNavbarLanguageForm extends Form {

    public function __construct($controller, $name, $fields = null, $actions = null) {

    $Laguages = array();

    foreach(LocaleGeoip::get_available_languages() as $Locale => $Language){
    $Languages[$Locale] = _t('BootstrapNavbarLanguageForm.'.$Language, $Language);
    }

    // Create fields
    $fields = new FieldList(
    $locale = new DropdownField('Locale', "", $Languages, i18n::get_locale())
    );
    $locale->addExtraClass('span2');
    // Create actions
    $actions = new FieldList(
    $submit = new FormAction('updateLang', _t('BootstrapNavbarLanguageForm.SUBMIT','BootstrapNavbarLanguageForm.SUBMIT'))
    );
    $submit->addExtraClass('btn');

    parent::__construct(
    $controller,
    $name,
    $fields,
    $actions
    );
    }

    public function updateLang(array $data){

    if($o_Member = Member::currentUser()) {

    $o_Member->Locale = $data['Locale'];

    $o_Member->write();
    }

    i18n::set_locale($data['Locale']);

    Session::set('Locale', $data['Locale']);

    Controller::curr()->redirectBack();
    }
    }

    Now I want this form to be used without the submit button. It just should submit on changing the dropdown. I know, I can work here with jQuery and that is not the problem.

    But how to I create the code and the submit actions, without adding a(visible) submit button?

    I can try to add an empty $action. But how do I tell the form, to use the updateLang method, when being submitted?

  • Andre
    Avatar
    Community Member
    126 Posts

    Re: Form Submit onChange without submit Button Link to this post

    Anyone with an idea here?

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Form Submit onChange without submit Button Link to this post

    Why not make the action (button) invisible using css?

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