本文整理汇总了PHP中sfForm::getFormattedErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP sfForm::getFormattedErrors方法的具体用法?PHP sfForm::getFormattedErrors怎么用?PHP sfForm::getFormattedErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfForm
的用法示例。
在下文中一共展示了sfForm::getFormattedErrors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$fieldSc = $form->getFormFieldSchema();
$widget = $fieldSc->getWidget();
$params = array();
foreach ($widget->getFields() as $key => $object) {
if ($key == "sf_guard_group_permission_list") {
continue;
}
$data = $request->getParameter($key);
$data_dec = json_decode($data);
$params[$key] = is_array($data_dec) ? $data_dec : $data;
}
$form->bind($params);
if ($form->isValid()) {
try {
$group = $form->save();
} catch (Exception $e) {
$response = array('success' => false, 'error' => 'Could not perform operation', 'agent' => sfConfig::get('config_acronym'), 'info' => 'Could not perform operation');
return $response;
}
return array('success' => true, 'object' => $group->toArray());
} else {
$errors = array();
foreach ($form->getFormattedErrors() as $error) {
$errors[] = $error;
}
$error_msg = implode($errors);
$info = implode('<br>', $errors);
$response = array('success' => false, 'error' => $error_msg, 'agent' => sfConfig::get('config_acronym'), 'info' => $info);
return $response;
}
}
示例2: processJsonForm
protected function processJsonForm($request, sfForm $form)
{
$form->bind($request);
if ($form->isValid()) {
try {
$etva_vlan = $form->save();
} catch (Exception $e) {
$result = array('success' => false, 'error' => array('vlan' => $e->getMessage()));
return $result;
}
//$result = array('success'=>true,'insert_id'=>$etva_server->getId());
$result = array('success' => true, 'object' => $etva_vlan);
return $result;
} else {
error_log("CREATEVLAN[ERROR] Form is invalid");
$errors = array();
foreach ($form->getFormattedErrors() as $error) {
$errors[] = $error;
}
$msg_err = implode('<br>', $errors);
$err = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => $msg_err);
$result = array('success' => false, 'agent' => sfConfig::get('config_acronym'), 'error' => array($err));
return $result;
}
}