admin管理员组

文章数量:1401499

I never used Javascript before but now I need it in my Symfony-Project (Symfony 1.4) and have some problems about where to add code to get it working:

I have a template (indexSuccess) in the module „aktionLimit“ where I show the values of the variables of an Object of the class „Aktion“ :

<p>Value1: <?php echo $aktion->getValue1()  ?></p>
<p>Value2: <?php echo $aktion->getValue2()  ?></p>
<p>Value3: <?php echo $aktion->getValue3()  ?></p>

<?php include_partial('form', array('form' => $form)) ?>

This is the executeIndex:

$this->aktion = AktionlimitPeer::getByName($this->getUser()->getAttribute('aktion'));

$aktionParam = new Aktion();
$aktionParam->setName($this->aktion->getName());

$this->form = new AktionlimitForm(array(), array("aktion" => $aktionParam));

The AktionLimitForm looks like this:

$aktionForm = new AktionForm($this->getOption('aktion'), array("limit" => true));

$this->embedForm('Aktion', $aktionForm);  

$this->widgetSchema['neuerWert']= new sfWidgetFormInputText();

The embedded AktionForm has just one element (a dropdown-box which includes the unique names of the objects of „Aktion“):

$this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' =>   AktionPeer::getTypes()),array('onchange' => '???'));

Whenever the user chooses another „aktion“ in the dropdown-box I want to load the current object „aktion“ (referenced by the name) in executeIndex and show its values (Value 1-3) in indexSuccess.(When submitting it leads to another action.)

I need a function which calls executeIndex in the onChange-Event. I probably have to declare the function in the web/js-folder, is this right?. But how do I call the function from the form? And how do I call an action in a JavaScript-Function?

I hope you understood what I've written – today I have some difficulties to explain this problem in English :) Could anybody help?

I never used Javascript before but now I need it in my Symfony-Project (Symfony 1.4) and have some problems about where to add code to get it working:

I have a template (indexSuccess) in the module „aktionLimit“ where I show the values of the variables of an Object of the class „Aktion“ :

<p>Value1: <?php echo $aktion->getValue1()  ?></p>
<p>Value2: <?php echo $aktion->getValue2()  ?></p>
<p>Value3: <?php echo $aktion->getValue3()  ?></p>

<?php include_partial('form', array('form' => $form)) ?>

This is the executeIndex:

$this->aktion = AktionlimitPeer::getByName($this->getUser()->getAttribute('aktion'));

$aktionParam = new Aktion();
$aktionParam->setName($this->aktion->getName());

$this->form = new AktionlimitForm(array(), array("aktion" => $aktionParam));

The AktionLimitForm looks like this:

$aktionForm = new AktionForm($this->getOption('aktion'), array("limit" => true));

$this->embedForm('Aktion', $aktionForm);  

$this->widgetSchema['neuerWert']= new sfWidgetFormInputText();

The embedded AktionForm has just one element (a dropdown-box which includes the unique names of the objects of „Aktion“):

$this->widgetSchema['name'] = new sfWidgetFormChoice(array('choices' =>   AktionPeer::getTypes()),array('onchange' => '???'));

Whenever the user chooses another „aktion“ in the dropdown-box I want to load the current object „aktion“ (referenced by the name) in executeIndex and show its values (Value 1-3) in indexSuccess.(When submitting it leads to another action.)

I need a function which calls executeIndex in the onChange-Event. I probably have to declare the function in the web/js-folder, is this right?. But how do I call the function from the form? And how do I call an action in a JavaScript-Function?

I hope you understood what I've written – today I have some difficulties to explain this problem in English :) Could anybody help?

Share Improve this question edited May 3, 2013 at 12:20 iamdto 1,37211 silver badges23 bronze badges asked May 3, 2013 at 9:30 alexalex 1432 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

First of all, consider upgrading to symfony 2.

Then, you don't need to configure this in the form type, if you decide to use jquery (nice javascript framework). with jquery you can bind events to elements very easy.

$(document).ready( function() {
    $('#id_of_the_form_field').change(function() {
        // to get the selected value
        var selected = $(this).val()

        // do your magic pony stuff
    });
});

To call your php actions from javascript, you need to make a ajax request to related route.

本文标签: