07/03/2012 10:03pm

PHP | Problem -


<?php

class CompanyEdit extends Page {
static $db = array();
static $has_one = array();
}

class CompanyEdit_Controller extends Page_Controller {

function CompanyEditForm() {

//create fields
$fields = new FieldSet(
new TextField('Name1', 'Name 1'),
new TextField('Name2', 'Name 2'),
new TextField('Address1', 'Address 1'),
new TextField('Address2', 'Address 2'),
new TextField('Regon', 'Regon'),
new TextField('Nip', 'Nip'),
new TextField('Website', 'Website'),
new TextField('Email', 'Email'),
new TextField('Phone1', 'Phone 1'),
new TextField('Phone2', 'Phone 2'),
new TextField('Fax1', 'Fax 1'),
new TextField('Fax2', 'Fax 2'),
new TextField('OrderCode', 'Order Code')
);

//create actions for form
$actions = new FieldSet(
new FormAction('CompanyEditApply', 'Save')
);

$Form = new Form($this, 'CompanyEditForm', $fields, $actions);

//populate company data to form
$Member = Member::currentMember();
$firma = $Member->get_by_id('Company',$Member->MyCompanyID);
$Form->loadDataFrom($firma->data());
return $Form;
}

function CompanyEditApply($data, $form) {
//is user logged
if($CurrentMember = Member::currentMember()) {
//TODO add field validators
$firma = $CurrentMember->get_by_id('Company',$CurrentMember->MyCompanyID);
$form->saveInto($firma);
$firma->write();
return Director::redirect($this->Link('?saved=1'));
}
else {
return Security::permissionFailure($this->controller, 'You have to be logged');
}
}

function Saved() {
return $this->request->getVar('saved');
}
}
?>


Post Comment