0

i have a problem, i cannot get values (added with $form->addField) from form in CRUD. I just get what's in the model, but there just isn't extra values...

MODEL:

class Model_Admin extends Model_Table {
    public $table ='admin';
    function init(){
        parent::init(); 
        $this->addField('name')->mandatory('Name required');
        $this->addField('email')->mandatory('Email required');
        $this->addField('password')->type('password')->mandatory('Password required');
    }
} 

On page i create extended CRUD and add two more fields:

$adminCRUD = $this->add('MyCRUD');
$adminCRUD->setModel('Admin');
if($adminCRUD->isEditing('add')){
    $adminCRUD->form->addField('line','test2','TEST LINE');
    $adminCRUD->form->addField('DropDown', 'appfield','Manages Applications')
        ->setAttr('multiple')
        ->setModel('Application');
}

Extended CRUD:

class MyRUD extends CRUD {
    function formSubmit($form)
    {
        //var_dump($form);
        var_dump($form->get('test2'));
        var_dump($form->get('appfield'));
        try {
            //$form->update();
            $self = $this;
            $this->api->addHook('pre-render', function () use ($self) {
                $self->formSubmitSuccess()->execute();
            });
        } catch (Exception_ValidityCheck $e) {
            $form->displayError($e->getField(), $e->getMessage());
        }
    }
}

I get null for $form->get('test2') or $form->get('appfield'). I checked whole $form object and there isn't values from test2.. Somwhere in the process gets lost (or droped), how to get it in extended CRUD?

Thanks in advance!

DarkSide
  • 3,670
  • 1
  • 26
  • 34
Peter
  • 728
  • 3
  • 16
  • 34
  • Did these 2 custom fields show up in Form visually? – DarkSide Jan 12 '14 at 15:27
  • Probably you add these fields "to late" in code flow. Not sure though - have to check more in details in ATK source. Or one more idea - if you use setModel, then form fields are taken only from that model and no other fields are submitted. – DarkSide Jan 12 '14 at 15:28
  • Yesm they show visually, i can use them to insert data. I even get values in $_POST, so i guess this is OK a workaround.. – Peter Jan 12 '14 at 17:11
  • I went thru with debugger.. Im totaly new to ATK, but what it seems to me that it initialize crud made on the page.php, even after add button pressed. But on this initialization it doesn't add these two elements: $adminCRUD->form->addField, so at the end they are not in the form elements (but probably should be..). Why this is like this is at the moment too much for me. Thanks for help DarkSide! – Peter Jan 12 '14 at 17:15
  • Maybe at first you can try to make this using simple Form not CRUD and see how it works then. I just don't have time today to do this and test :( – DarkSide Jan 12 '14 at 17:43

0 Answers0