本文整理汇总了PHP中sfForm::getErrorSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP sfForm::getErrorSchema方法的具体用法?PHP sfForm::getErrorSchema怎么用?PHP sfForm::getErrorSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfForm
的用法示例。
在下文中一共展示了sfForm::getErrorSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderGlobalErrors
/**
* A central place to render global errors for both BaseFormPropel subclasses, and mySfForm subclasses.
* Works in conjunction with hasGlobalErrors above.
* @param sfForm $form
* @return string The errors, formatted appropriately.
*/
public static function renderGlobalErrors($form)
{
//$globalErrorsText = parent::renderGlobalErrors();
$globalErrorsText = '';
//treat any error as a global error.
$nonGlobalErrors = $form->getErrorSchema()->getErrors();
$nonGlobalErrorCount = count($nonGlobalErrors);
if ($nonGlobalErrorCount > 0) {
//$globalErrorsText .= '(1) ';//<br />The following fields are required: ';
$count = 1;
////print_r($nonGlobalErrors);
foreach ($nonGlobalErrors as $key => $nonGlobalError) {
//$globalErrorsText .= '<br />'.$key . ': ' . $nonGlobalError->getMessage() . '<br />';
$labelName = '';
if (isset($form[$key])) {
$labelName = $form[$key]->renderLabelName();
}
$globalErrorsText .= $labelName . ': ' . $nonGlobalError . ' ';
//put a comma after each if it isn't the last, otherwise a full stop.
if ($count < $nonGlobalErrorCount) {
//$globalErrorsText .= sprintf(" (%s) ", $count+1);
} else {
$globalErrorsText .= ".";
}
$count++;
}
}
return $globalErrorsText;
}
示例2: checkCSRFProtection
/**
* @see sfWebRequest
*/
public function checkCSRFProtection()
{
try {
parent::checkCSRFProtection();
} catch (sfValidatorErrorSchema $e) {
// retry checking for using sfForm (just for BC)
$form = new sfForm();
$form->bind($form->isCSRFProtected() ? array($form->getCSRFFieldName() => $this->getParameter($form->getCSRFFieldName())) : array());
if (!$form->isValid()) {
throw $form->getErrorSchema();
}
}
}
示例3: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
try {
$item = $form->save();
$this->redirect('loanitem/edit?id=' . $item->getId());
} catch (Doctrine_Exception $ne) {
$e = new DarwinPgErrorParser($ne);
$error = new sfValidatorError(new savedValidator(), $e->getMessage());
$form->getErrorSchema()->addError($error);
}
}
}
示例4: additionalFailureDescription
/** Return additional failure description where needed
*
* The function can be overritten to provide additional failure information
* like a diff
*
* @param sfForm $form Evaluated value or object.
* @return string
*/
protected function additionalFailureDescription($form)
{
/* If the form has errors, add them to the message, since that's what we're
* going to be interested in when the assertion fails).
*
* Note that we only have to check for this if we were expecting the form to
* be valid (give it a second; it'll come to you).
*/
if ($this->_expected and $errors = $form->getErrorSchema()->getErrors()) {
return sprintf('Form has errors:%s%s', PHP_EOL, print_r(array_map('strval', $errors), true));
}
return '';
}
示例5: processForm
protected function processForm(sfForm $form, $data = array())
{
$form->bind($data);
if ($form->isValid()) {
try {
$report = $form->save();
return $report;
} catch (Doctrine_Validator_Exception $e) {
$errorStack = $form->getObject()->getErrorStack();
$message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
foreach ($errorStack as $field => $errors) {
$message .= "{$field} (" . implode(", ", $errors) . "), ";
}
$message = trim($message, ', ');
throw new sfException($message);
}
} else {
if ($es = $form->getErrorSchema()) {
throw new sfException($es->getMessage());
}
throw new sfException('The item has not been saved due to some errors.');
}
}
示例6: processJsonForm
protected function processJsonForm(sfWebRequest $request, sfForm $form, $form_data = null)
{
$params = (array) json_decode($request->getParameter($form->getName()));
if (!$form_data) {
$form_data = $params;
}
$form->bind($form_data);
//$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
//$params = $request->getParameter($form->getName());
if ($form->isValid()) {
try {
$etva_node = $form->save();
$uuid = $etva_node->getUuid();
$result = array('success' => true, 'uuid' => $uuid, 'keepalive_update' => sfConfig::get('app_node_keepalive_update'), 'object' => $etva_node);
//notify system log
$message = Etva::getLogMessage(array('name' => $etva_node->getName(), 'uuid' => $uuid, 'keepalive_update' => $result['keepalive_update']), EtvaNodePeer::_OK_SOAPINIT_);
$this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::INFO)));
} catch (Exception $e) {
$result = array('success' => false, 'error' => array('node' => $e->getMessage()), 'obj' => $etva_node);
}
return $result;
} else {
$errors = array();
foreach ($form->getErrorSchema() as $field => $error) {
$errors[$field] = $error->getMessage();
}
$result = array('success' => false, 'error' => $errors);
//notify system log
$message = Etva::getLogMessage(array('name' => $params['name'], 'uuid' => $params['uuid']), EtvaNodePeer::_ERR_SOAPINIT_);
$this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
return $result;
}
}
示例7: formatErrorMessage
/**
* Собирает в строку сообщения об ошибках
*
* @param sfForm $form
* @param array $errors
* @return string
*/
protected function formatErrorMessage(sfForm $form, array $errors)
{
return ($errors ? "[Invalid.] " . implode(" [Invalid.] ", $errors) : "") . (strlen($form->getErrorSchema()) ? ($errors ? " " : "") . $form->getErrorSchema() : "");
}
示例8: checkCSRFProtection
public function checkCSRFProtection()
{
$form = new sfForm();
$form->bind($form->isCSRFProtected() ? array($form->getCSRFFieldName() => $this->getParameter($form->getCSRFFieldName())) : array());
if (!$form->isValid()) {
throw $form->getErrorSchema();
}
}
示例9: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$updated = $form->getObject()->isNew() ? 'created' : 'updated';
$invoice = $form->save();
// update totals with saved values
$invoice->refresh(true)->setAmounts()->save();
$this->getUser()->info("The recurring invoice was {$updated} successfully.");
$this->redirect('recurring/edit?id=' . $invoice->id);
} else {
foreach ($form->getErrorSchema()->getErrors() as $k => $v) {
$this->getUser()->error(sprintf('%s: %s', $k, $v->getMessageFormat()));
}
$this->getUser()->error('The recurring invoice has not been saved due to some errors.');
}
}
示例10: processForm
protected function processForm(sfWebRequest $request, sfForm $form, $action = 'create')
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
try {
$wasNew = $form->isNew();
$autoCodeForUpdate = false;
if (!$wasNew) {
$collection = Doctrine::getTable('Collections')->findOneById($form->getObject()->getCollectionRef());
$autoCodeForUpdate = !$collection->getCodeAutoIncrementForInsertOnly();
}
$specimen = $form->save();
if ($wasNew || $autoCodeForUpdate) {
Doctrine::getTable('Collections')->afterSaveAddCode($specimen->getCollectionRef(), $specimen->getId());
}
$this->redirect('specimen/edit?id=' . $specimen->getId());
} catch (Doctrine_Exception $ne) {
if ($action == 'create') {
//If Problem in saving embed forms set dirty state
$form->getObject()->state('TDIRTY');
}
$e = new DarwinPgErrorParser($ne);
$extd_message = '';
if (preg_match('/unique constraint "unq_specimens"/i', $ne->getMessage())) {
$dup_spec = Doctrine::getTable('Specimens')->findDuplicate($form->getObject());
if (!$dup_spec) {
$this->logMessage('Duplicate Specimen not found: ' . json_encode($form->getObject()->toArray()), 'err');
} else {
$extd_message = '<br /><a href="' . $this->getController()->genUrl('specimen/edit?id=' . $dup_spec->getId()) . '">' . $this->getI18N()->__('Go the the original record') . '</a>';
}
}
$error = new sfValidatorError(new savedValidator(), $e->getMessage() . $extd_message);
$form->getErrorSchema()->addError($error, 'Darwin2 :');
}
}
}
示例11: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$isNew = $this->ei_block_param->isNew();
$this->ei_block_param = $form->save();
if ($isNew) {
$this->ei_block_param->getNode()->insertAsLastChildOf($this->ei_block_parent);
}
return false;
} else {
$JSONResponse['status'] = "error";
$errors = $form->getErrorSchema()->getErrors();
$JSONResponse['message'] = "Unable to save the parameter. " . $errors['name'];
}
return $JSONResponse;
}
示例12: getErrores
protected function getErrores(sfForm $form)
{
#$fields = $form->getWidgetSchema()->getFields();
$oParcial = $form->getErrorSchema()->getNamedErrors();
$aParcial = array();
$oGlobal = $form->getErrorSchema()->getGlobalErrors();
$aGlobal = array();
#$form_name = $form->getName();
foreach ($oParcial as $n => $e) {
#if(!$form->offsetExists($n) || $fields[$n]->isHidden())
# $aGlobal[$form_name.'_global_error'] = $e->getMessage();
#else
# $aParcial[$form_name.'_'.$n.'_error'] = $e->getMessage();
return $e->getMessage();
}
foreach ($oGlobal as $n => $e) {
#$aGlobal[$form_name.'_global_error'] = $e->getMessage();
return $e->getMessage();
}
#$errors = array_merge($aParcial, $aGlobal);
#return $errors;
}
示例13: processForm
protected function processForm(sfWebRequest $request, sfForm $form, $celulaId = null)
{
$asistencia = $request->getParameter('reunion')['asistencias'];
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
$fields = $form->getFormFieldSchema()->getValue();
if ($form->isValid()) {
$reunion = $form->save();
foreach ($reunion->getAsistencias() as $borrable) {
$borrable->delete();
}
$asistencias = explode(',', $asistencia);
foreach ($asistencias as $key => $asistencia) {
if ($asistencia > 0) {
$source = new Asistencia();
$source->setReunionId($reunion->getId());
$source->setMiembroCelulaId($asistencia);
$source->save();
}
}
$this->getUser()->setFlash('notice', "Reunión guardada exitosamente", true);
if (isset($celulaId)) {
$this->redirect('celulas/show?id=' . $celulaId);
} else {
$this->forward('celulas', 'index');
}
}
$this->getUser()->setFlash('error', "Error!!! " . $form->getErrorSchema(), true);
if (isset($celulaId)) {
$this->redirect('celulas/show?id=' . $celulaId);
} else {
$this->forward('celulas', 'index');
}
}
示例14: processJsonForm
protected function processJsonForm(sfWebRequest $request, sfForm $form, $form_data = null)
{
if (!$form_data) {
$form_data = (array) json_decode($request->getParameter($form->getName()));
}
$form->bind($form_data);
if ($form->isValid()) {
// if default cluster changed
if ($form_data['isDefaultCluster']) {
$updatecluster = array('Isdefaultcluster' => 0);
EtvaClusterQuery::create()->update($updatecluster);
}
try {
$etva_cluster = $form->save();
$result = array('success' => true, 'object' => $etva_cluster);
} catch (Exception $e) {
$result = array('success' => false, 'error' => array('cluster' => $e->getMessage()), 'obj' => $etva_cluster);
return $result;
}
return $result;
} else {
$errors = array();
foreach ($form->getErrorSchema() as $field => $error) {
$errors[$field] = $error->getMessage();
}
//notify system log
$msg_i18n = Etva::makeNotifyLogMessage(sfConfig::get('config_acronym'), EtvaClusterPeer::_ERR_UPDATE_, array('name' => $form_data['name'], 'info' => $this->setJsonError($errors)));
$result = array('success' => false, 'error' => $msg_i18n, 'info' => $msg_i18n);
return $result;
}
}
示例15: processJsonForm
/**
*
* process server form data. binds request data with form and save
*
* @param sfWebRequest $request A request object
* @param sfForm $form A form object
*
*/
protected function processJsonForm(sfWebRequest $request, sfForm $form)
{
// get submitted form elements
$form_elems = $request->getParameter($form->getName());
// retrieve mac pool elements number
// $mac_pool = $request->getParameter('mac_pool');
//generate random macs and add to form elements
// if(isset($mac_pool)){
// $macs = $this->generateMacPool($mac_pool);
// $macs = implode(',',$macs);
//
// $form_elems['mac_addresses'] = $macs;
// }
$form->bind($form_elems, $request->getFiles($form->getName()));
if ($form->isValid()) {
$etva_server = $form->save();
//$result = array('success'=>true,'insert_id'=>$etva_server->getId());
$result = array('success' => true, 'object' => $etva_server->toArray());
return $result;
} else {
$errors = array();
foreach ($form->getErrorSchema() as $field => $error) {
$errors[$field] = $error->getMessage();
}
$result = array('success' => false, 'error' => $errors);
return $result;
}
}