<?php /* Add ah_postings package */ $path = MODX_CORE_PATH . 'components/ah_postings/'; $result = $modx->addPackage('ah_postings',$path . 'model/','vw_ah_pos_'); /* Create new posting object */ $position = $modx -> newObject('Postings'); if (!is_object($position) || !($position instanceof xPDOObject)) { $errorMsg='Failed to create object of type:Postings '; $hook->addError('error_message',$errorMsg); return false; } return true;
&hooks = `snippetname,email`
[[!+fi.error_message:notempty=`<div id="update-message">[[!+fi.error_message]]</div>`]] [[!+fi.successMessage:notempty=`<div id="update-message">[[!+fi.successMessage]]</div>`]]
<?php /* Add ah_postings package and throw an error if unsuccessful */ $path = MODX_CORE_PATH . 'components/ah_postings/'; $result = $modx->addPackage('ah_postings',$path . 'model/','vw_ah_pos_'); if (! $result) { $errorMsg='Failed to add package '; $hook->addError('error_message',$errorMsg); return false; } /* Create new posting object & check if object was created or else throw an error */ $position = $modx -> newObject('Postings'); if (!is_object($position) || !($position instanceof xPDOObject)) { $errorMsg='Failed to create object of type:Postings '; $hook->addError('error_message',$errorMsg); return false; } /* Set data from form */ $position->set('usr', $_POST['usr']); /* Save data from form and throw out errors if fails */ if (!$position->save()) { $errorMsg='Failed to save object '; $hook->addError('error_message',$errorMsg); return false; } else return true;
Placeholder in form: [[fi.usr]] Database field name: usr
<?php $xpdo_meta_map['Postings']= array ( 'package' => 'ah_postings', 'version' => '1.1', 'table' => 'postings', 'fields' => array ( 'id' => NULL, 'usr' => NULL, 'department' => NULL, 'duration' => NULL, 'renumeration' => NULL, 'apply-method' => NULL, 'interns' => NULL, 'date' => NULL, ), 'fieldMeta' => array ( 'id' => array ( 'dbtype' => 'int', 'precision' => '10', 'attributes' => 'unsigned', 'phptype' => 'integer', 'null' => false, 'index' => 'pk', ), 'usr' => array ( 'dbtype' => 'int', 'precision' => '10', 'attributes' => 'unsigned', 'phptype' => 'integer', 'null' => false, ), 'department' => array ( 'dbtype' => 'varchar', 'precision' => '255', 'phptype' => 'string', 'null' => false, ), 'duration' => array ( 'dbtype' => 'int', 'precision' => '10', 'attributes' => 'unsigned', 'phptype' => 'integer', 'null' => false, ), 'renumeration' => array ( 'dbtype' => 'int', 'precision' => '1', 'attributes' => 'unsigned', 'phptype' => 'integer', 'null' => false, ), 'apply-method' => array ( 'dbtype' => 'int', 'precision' => '1', 'attributes' => 'unsigned', 'phptype' => 'integer', 'null' => false, ), 'interns' => array ( 'dbtype' => 'int', 'precision' => '100', 'phptype' => 'integer', 'null' => false, ), 'date' => array ( 'dbtype' => 'varchar', 'precision' => '10', 'phptype' => 'string', 'null' => false, ), ), 'indexes' => array ( 'PRIMARY' => array ( 'alias' => 'PRIMARY', 'primary' => true, 'unique' => true, 'type' => 'BTREE', 'columns' => array ( 'id' => array ( 'length' => '', 'collation' => 'A', 'null' => false, ), ), ), ), );
$position -> set('usr', $_POST['fi.usr']);
$position -> set('id', '999');