Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
way to rewrite $_properties before entering fieldset
  • Hello, im looked at the tut from http://net.tutsplus.com/tutorials/php/easy-form-generation-using-fuelphp/ and ive seen that you can setup custom attributes in model definition in $_properties. My question is, is there a way to change the $_properties property dynamicly before adding it to the fieldset? $fieldset = Fieldset::forge()->add_model('Model_Post');
    $form = $fieldset->form();
    class Model_Post extends \Orm\Model
    {
    protected static $_table_name = 'posts'; protected static $_primary_key = array('id'); protected static $_properties = array(
    'id',
    'post_title' => array( //column name
    'data_type' => 'string',
    'label' => 'Post Title', //label for the input field
    'validation' => array('required', 'max_length'=>array(100), 'min_length'=>array(10)) //validation rules
    ),
    'post_content' => array(
    'data_type' => 'string',
    'label' => 'Post Content',
    'validation' => array('required'),
    'form' => array('type' => 'textarea'),
    ),
    'author_name' => array(
    'data_type' => 'string',
    'label' => 'Author Name',
    'validation' => array('required', 'max_length'=>array(65), 'min_length'=>array(2))
    ),
    'author_email' => array(
    'data_type' => 'string',
    'label' => 'Author Email',
    'validation' => array('required', 'valid_email')
    ),
    'author_website' => array(
    'data_type' => 'string',
    'label' => 'Author Website',
    'validation' => array('required', 'valid_url', 'max_length'=>array(60))
    ),
    'post_status' => array(
    'data_type' => 'string',
    'label' => 'Post Status',
    'validation' => array('required'),
    'form' => array('type' => 'select', 'options' => array(1=>'Published', 2=>'Draft')),
    ) );
    }
  • $fieldset->field('post_status')->set_options(array(1=>'Published', 2=>'Draft'));
  • thank you! that solved my problem! But now i get a notice:
    Notice! ErrorException [ Notice ]: Undefined offset: 3 COREPATH/classes/fieldset/field.php @ line 294: 293: {
    294: if (is_array($array[$k]) and is_array($v))
    295: {
  • What do you want to change? You can disable fields from being rendered by setting their type to false, either in the model or later:
    $fieldset = Fieldset::forge()->add_model('Model_Post');
    $fieldset->field('post_status')->set_type(false);
    

    And many similar modifications can be made this way.
  • for example if i want the selectbox have dynamic options isntead of fixed. Is there way to change that dynamicly?

Howdy, Stranger!

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

In this Discussion