55 define(
'REST_INSERT_VALIDATION_ERROR', 501);
58 if ( !defined(
'DISABLE_reCAPTCHA') ) define(
'DISABLE_reCAPTCHA', 1);
59 import(
'Dataface/QuickForm.php');
62 $query =
$app->getQuery();
68 if ( !@$_POST[
'-table'] ){
69 throw new Exception(
"No table specified");
76 $tableObj = $rec->_table;
79 if ( !$rec->checkPermission(
'new') ){
80 throw new Exception(
"Failed to insert record. Permission denied");
82 foreach ($_POST as $k=>$v){
83 if ( $k{0} ==
'-' )
continue;
85 $rec->setValue($k, $v);
86 if ( !$rec->checkPermission(
'new', array(
'field'=>$k) ) ){
87 throw new Exception(sprintf(
"Failed to insert record because you do not have permission to insert data into the %s column", $k));
94 $form->_flagSubmitted =
true;
95 $res = $form->validate();
97 $errors = $form->_errors;
105 $res = $rec->save(null,
true);
107 throw new Exception(
"Failed to insert record due to a server error: ".$res->getMessage(), 500);
111 $vals = $rec->strvals();
112 foreach ($vals as $k=>$v){
113 if ( $rec->checkPermission(
'view') ){
120 'message'=>
'Record successfully inserted',
126 }
catch (Exception $ex){
128 'code'=>$ex->getCode(),
129 'message'=>$ex->getMessage(),
139 echo json_encode($params);