Submit ajax form with custom method or handle?

3 years ago

droa22
Member | 6
+
0
-

Imagine one component that make one view with snippets and one form submitted with ajax.
What is the best solution when I have form that makes changes in one snippet of the same view?.

<?php
protected function createComponentMyCustomForm()
{
    $form = new MyCustomForm();
    $form->onSuccess[] = array($this, 'myCustomFormSubmitted');
    return $form;
}

public function myCustomFormSubmitted(MyCustomForm $form)
{
    //some changes in db with form values
    $this->redrawControl('mySnippet');
}
?>

or

<?php
protected function createComponentMyCustomForm()
{
    $form = new MyCustomForm();
    $form->onSuccess[] = array($this, 'handleMyCustomFormSubmitted');
    return $form;
}

public function handleMyCustomFormSubmitted(MyCustomForm $form)
{
    //some changes in db with form values
    $this->redrawControl('mySnippet');
}
?>

the template:

<?php
{control registrationForm, class => 'ajax'}

{snippet mySnippet}
    {* Show some data from db *}
{snippet}
?>

3 years ago

Pavel Kravčík
Member | 959
+
+1
-

I prefer first example, cause there will be no problem if you do this in template:

n:href="handleMyCustomFormSubmitted!"