Documentation 2.x and 3.x

Simple form post in administration area

This example shows how to create additional tab in administration area with custom form and controller. Read coments in code.

Comments (2)

Tomas

Tomas

Hi,

I am totaly new to php, love the plugin, it works liek a charm.
I've googled a lot, and modified the code here below: public function post ($controller, $instanceId, $postData, $data) {

//to validate posted data, we need to create the same form object that has been used to generate the form
$form = $this->createForm($instanceId);

//get array of errors
$errors = $form->validate($postData);
{
$dbh = \Ip\Db::getConnection();
$sql = '
INSERT INTO
`'.DB_PREF.'m_examples_address_book`
SET
`email` = :email
';

$params = array (
'email' => $postData[email]
);
$q = $dbh->prepare($sql);
$q->execute($params);
}
if ($errors) {
$answer = array(
'status' => 'error',
'errors' => $errors
);
} else {
//do whathever you want with $postData. Send via email, write to database.

$answer = array(
'status' => 'success'
);
}

//retun answer in JSON format
$controller->returnJson($answer);
}

}


The thing is that I don't see the success message anymore.. Could you take a look please? I've spent hours...

Mangirdas

Mangirdas

Check Administrator -> Log tab in admin to see if there are any errors.

Also you had to put your custom code on line "//do whathever you want with $postData. Send via email, write to "

And the most important thing: this section is used to comment and fine tune documentation page. Problem have to be reported on our answers section http://www.impresspages.org/cms/answers/ Answers has notifications by email, code highlighting.

Write a comment

You must be logged in to comment.