Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
how to accessing the generated fieldset (in the view) from the controller
  • hi, i have a large amount of forms, so i put each form in it view, then i use the fieldset to generate the forms inside views, with validation too , so  how can access those forms from the controller, to validate and do models processing (without ORM)
  • in th view : 



    $form = Fieldset::forge('my_form');
    $fieldset = array(
    'username'=>array(
    array(),//attrs
    array('required')//rules
    ),
    ....
    );
    foreach($fieldset as $field=>$params){

    $attrs = Arr::get($params,0);
    $rules = Arr::get($params,1);
    $form -> add($field, $field, $attrs, $rules);
    }
    $form -> add('action', NULL, array('type' => 'hidden', 'value' => 'action_name'));
    $form -> add('submit', NULL, array('type' => 'submit', 'class' => 'right button', 'value' => 'submit' ));

    if (Input::post('action') == 'action_name') {

    if(!$form->validation()->run()){
    echo $form->show_errors();
    $form -> repopulate();
    }
    }

    echo $form -> build();


    then i want to do the CRUD inside the controller  like this:


    public function action_actions() {



    if (Input::post('action') == 'action_name') {
    $form = Fieldset::Instance('my_form');
    if($form->validation()->run()){

    Model_Actions::add($form->validated());

    Response::redirect(Uri::create('actions/welcome'));

    }

    }
    .....
  • HarroHarro
    Accepted Answer
    Don't generate the fieldset in the view. You should not have any logic in the view, views are about presentation.
  • thank you.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion