Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
how to pass parameter in the Form from Views
  • how to pass parameter in the Form  from Views

    in Form

    echo Form::input('name', 'value', array('style' => 'border: 2px;'));

    I need to
    echo Form::input('name', $value, array('style' => 'border: 2px;'));

  • In your controller:

    View::forge('myview', array('value' => 'please type in a  name'));

    Every key you pass in the data array (like 'value' in this example) becomes a local variable in the view.
  • in this I figured out but the problem is that the variable from the View
    is not transmitted in the Form, I did not find in the documentation how
    to do this
  • the form is defined in a separate file  _form.php  like this

    <?php echo Form::open();  ?>

        <fieldset>
            <div class="clearfix">
                <?php echo Form::label('Slug', 'slug'); ?>

                <div class="input">
                    <?php echo Form::input('slug', Input::post('title', isset($category) ? $category->slug : ''), array('class' => 'span4')); ?>

                </div>
            </div>
           
            <div class="clearfix">
                <?php echo Form::label('Description', 'description'); ?>

                <div class="input">
                    <?php echo Form::textarea('description', Input::post('description', isset($category) ? $category->description : ''), array('class' => 'span8', 'rows' => 8)); ?>

                </div>
            </div>
            <div class="actions">
                <?php echo Form::submit('submit', 'Да', array('class' => 'btn btn-primary')); ?>

            </div>
        </fieldset>
    <?php echo Form::close(); ?>


  • in View

    <?php  echo render('categories/_form'); ?>
  • once again describe the problem

    controller/categories
    <?php

    class Controller_Categories extends Controller_Template
    {

        public $template = 'template_base';
        
        public function action_index()
        {
           
             
        }

        

        
        public function action_edit($id = null)
        {
            --------
                      
            
                    $data['categories'] = $category->toArray();
                    --------
                        
                   

            $this->template->title = "Категории";
            $this->template->content = View::forge('categories/edit', $data);

        }


    Vies   /categories/edit.php


    <?php

     echo render('categories/_form', $categories);

    here everything is right but in

    categories/_form

    variable $categories disappears



    what I'm doing wrong of course there is nothing in the documentation?

  • solved the problem

    Vies   /categories/edit.php


    <?php
     $data['category'] = $category;
     echo render('categories/_form', $data);

    everything proved to be simply unusually organized by passing parameters


  • HarroHarro
    Accepted Answer
    You didn't mention you had nested views, otherwise I could have pointed this out directly.

    The standard Oil code (that generates the create/edit construction with the separate _form view) relies on global view variables, which solves the issue of passing view data from one to the next.

    I don't like global vars, so I never use them. That however means you have to pass the data on manually.

    If you're on PHP 5.4+, you can use this to pass all view variables on the the child view:

    echo render('categories/_form', $this->get_data());

    If you're not on PHP 5.4, you can use this as a workaround:

    echo render('categories/_form', $__data);

    Obviously, you can also do it on a per-variable basis, like you have solved it now.

Howdy, Stranger!

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

In this Discussion