/** * edit action: edit a person * * @param $id id of the person record to edit * @throws none * @returns void */ public function action_edit($id = null) { // edit cancelled? \Input::post('cancel', false) !== false and \Response::redirect('mymodule/people'); // get the user record we want to edit if ( ! $people = Model\Person::find($id)) { // bail out with an error if not found \Messages::error(__('people.not-found')); \Response::redirect('mymodule/people'); } // create the model fieldset $form = \Fieldset::forge('form'); $form->add_model('Mymodule\\Model\\Person'); // do we have input? if (\Input::post()) { // validate the input $form->validation()->run(); // if validated, save the updates if ( ! $form->validation()->error()) { // get the validated data, and get rid of null values $data = array_filter($form->validated(), function($item){ return $item !== null; }); // custom data processing here... // update the people record $people->from_array($data); // and save it if ($people->save()) { \Messages::success(sprintf(__('people.updated'), $people->surname.', '.$people->initials.' '.$people->prefix)); \Response::redirect('mymodule/people'); } else { \Messages::error(__('people.updated-failed')); } } else { // inform the user validation failed \Messages::error(__('people.form.errors')); } // repopulate the form from the posted data $form->repopulate(); } else { // populate the form with the existing data $form->populate($people); } // return the view and pass our fieldset return \Viewmodel::forge('people/edit')->set('form', $form, false); }
It looks like you're new here. If you want to get involved, click one of these buttons!