本文整理汇总了PHP中sfForm类的典型用法代码示例。如果您正苦于以下问题:PHP sfForm类的具体用法?PHP sfForm怎么用?PHP sfForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sfForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$params = $request->getParameter($form->getName());
$this->forward404Unless($this->location = Doctrine::getTable('Location')->find(array($params['location_id'])), sprintf('Location does not exist (%s).', $params['location_id']));
$form->bind($params);
if ($form->isValid()) {
$detailsData = (array) json_decode($form->getValue('details'));
$photosData = (array) json_decode($form->getValue('photos'));
print_r($photosData);
die;
$form->save()->updateDetails($detailsData)->updatePhotos($photosData);
BotNet::create()->spammed($form->getObject(), 'description', $form->getObject()->getLocation()->getDateTimeObject('created_at')->format('U'));
if ($cache = $this->getContext()->getViewCacheManager()) {
$cache->remove('@sf_cache_partial?module=profit&action=_last&sf_cache_key=profit', '', 'all');
}
$this->redirect('profit/show?id=' . $form->getObject()->getId());
} else {
// foreach ($form->getFormFieldSchema() as $name => $formField) {
// if ($formField->getError() != "") {
// echo "ActionClassName::methodName( ): Field Error for :" . $name . " : " . $formField->getError();
// }
// }
}
return null;
}
示例2: embedWidgetIntoForm
/**
* Embeds this widget into the form. Sets label and validator for this widget.
* @param sfForm $form
*/
public function embedWidgetIntoForm(sfForm &$form)
{
$widgetSchema = $form->getWidgetSchema();
// $validatorSchema = $form->getValidatorSchema();
$widgetSchema[$this->attributes['id']] = $this;
// $widgetSchema[$this->attributes['id']]->setLabel(ucwords(str_replace("_", " ", $this->attributes['id'])));
}
示例3: doPreSave
protected function doPreSave(Doctrine_Record $record, sfForm $form)
{
// loop through relations
if ($relations = $form->getOption('dynamic_relations')) {
foreach ($relations as $field => $config) {
$collection = $record->get($config['relation']->getAlias());
// collect form objects for comparison
$search = array();
foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) {
$search[] = $embed->getObject();
}
foreach ($collection as $i => $object) {
if (false === ($pos = array_search($object, $search, true))) {
// if a related object exists in the record but isn't represented
// in the form, the reference has been removed
$collection->remove($i);
// if the foreign column is a notnull columns, delete the object
$column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName());
if ($object->exists() && isset($column['notnull']) && $column['notnull']) {
$object->delete();
}
}
}
}
}
}
开发者ID:rschumacher,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:26,代码来源:sfDoctrineDynamicFormRelationsListener.class.php
示例4: configure
public function configure()
{
$object = $this->getObject();
$this->useFields(array('egreso', 'complicaciones', 'riesgoqx_id', 'contaminacionqx_id', 'eventoqx_id', 'clasificacionqx', 'destino_px', 'status', 'ev_adversos_anestesia'));
//$this->widgetSchema['paciente_id'] = new sfWidgetFormInputHidden();
$this->widgetSchema['egreso'] = new sfWidgetFormInputText();
$this->widgetSchema['complicaciones'] = new sfWidgetFormTextarea();
$this->widgetSchema['status'] = new sfWidgetFormInputHidden();
$this->widgetSchema['status']->setAttribute('value', '100');
$this->setWidget('destino_px', new sfWidgetFormChoice(array('choices' => array('Recuperación', 'Intensivos', 'Sala', 'Defunción'), 'expanded' => true)));
$this->setWidget('clasificacionqx', new sfWidgetFormChoice(array('choices' => array(null, 'Mayor', 'Menor'), 'expanded' => false)));
$this->widgetSchema->setLabels(AgendaPeer::getLabels());
/* Ajustes a los validadores */
$this->validatorSchema['egreso']->setOption('required', true);
$this->validatorSchema['egreso']->setMessage('required', 'Falta hora');
// Agregando las personas del transoperatorio
$this->widgetSchema['egreso']->setAttributes(array('id' => 'datahora'));
$transPersonal = $object->getPersonalTransoperatorio();
$tmp = new sfForm();
if ($transPersonal != null) {
foreach ($transPersonal as $personal) {
if ($personal->getPersonalNombre()) {
$x = new PersonalcirugiaForm($personal);
$x->useFields(array('finaliza', 'personal_nombre'));
$tmp->embedForm('personal' . $personal->getId(), $x);
}
}
$this->embedForm('temporal', $tmp);
}
$this->validatorSchema['clasificacionqx']->setOption('required', true);
$this->validatorSchema['clasificacionqx']->setMessage('required', 'Falta clasificación de la cirugía');
}
示例5: processForm
protected function processForm(sfWebRequest $request, sfForm $form, $new = false)
{
$req_param = $request->getParameter($form->getName());
$req_param['login']['login'] = strtolower($req_param['login']['login']);
if (!isset($req_param['login']['is_moderator'])) {
$req_param['login']['is_moderator'] = 'off';
}
if (!isset($req_param['login']['locked']) || is_null($req_param['login']['locked'])) {
$req_param['login']['locked'] = 0;
}
$form->bind($req_param);
if ($form->isValid()) {
if (!$form->getObject()->isNew() || ModeratorManagement::checkForDoubloon($req_param['login']['login'])) {
$moderator = $form->save();
if ($new) {
ModeratorManagement::createXML($moderator->getLogin()->getLogin());
$this->getUser()->setFlash('notice', 'The moderator has been added.');
} else {
$this->getUser()->setFlash('notice', 'The moderator has been updated.');
}
$this->redirect('moderator/index');
} else {
$this->getUser()->setFlash('error', 'This login already exists, please choose another.');
}
} else {
$this->getUser()->setFlash('error', 'Required field(s) are missing or some field(s) are incorrect.', false);
}
}
示例6: doPreSave
protected function doPreSave(Doctrine_Record $record, sfForm $form)
{
// loop through relations
if ($relations = $form->getOption('dynamic_relations')) {
foreach ($relations as $field => $config) {
$collection = $record->get($config['relation']->getAlias());
// collect form objects for comparison
$search = array();
try {
foreach ($form->getEmbeddedForm($field)->getEmbeddedForms() as $i => $embed) {
$search[] = $embed->getObject();
}
} catch (InvalidArgumentException $e) {
// previously embedded form was removed at the end of form.filter_values as there were no values for it.
// @see sfDoctrineDynamicFormRelations::correctValidators()
}
foreach ($collection as $i => $object) {
$pos = array_search($object, $search, true);
if (false === $pos && $this->filterObject($object, $config['arguments'])) {
// if a related object exists in the record but isn't represented
// in the form, the reference has been removed
$collection->remove($i);
// if the foreign column is a notnull columns, delete the object
$column = $config['relation']->getTable()->getColumnDefinition($config['relation']->getForeignColumnName());
if ($object->exists() && isset($column['notnull']) && $column['notnull']) {
$object->delete();
}
}
}
}
}
}
开发者ID:AUTOPLANNING,项目名称:sfDoctrineDynamicFormRelationsPlugin,代码行数:32,代码来源:sfDoctrineDynamicFormRelationsListener.class.php
示例7: processForm
protected function processForm(sfWebRequest $request, sfForm $form, $emetteur, $asso)
{
$parameters = $request->getParameter($form->getName());
$form->bind($parameters, $request->getFiles($form->getName()));
if ($form->isValid()) {
$montant = abs($parameters['montant']);
var_dump(Doctrine);
$t = new Transaction();
// Transaction côté asso
$t_e = new Transaction();
// Transaction côté pôle
// Asso
$t->Asso = $asso;
$t_e->Asso = $emetteur;
// Compte
$t->compte_id = $parameters['asso_compte_id'];
$t_e->compte_id = $parameters['emetteur_compte_id'];
// Libellé
$t_e->libelle = sprintf('Avance de Trésorie %s', $asso->getName());
$t->libelle = sprintf('Avance de Trésorie %s', $emetteur->getName());
$t_e->montant = -($t->montant = $montant);
$t_e->commentaire = $t->commentaire = $parameters['commentaire'];
$t->moyen_id = $t_e->moyen_id = $parameters['moyen_id'];
$t->moyen_commentaire = $t_e->moyen_commentaire = $parameters['moyen_commentaire'];
$t->date_transaction = $t_e->date_transaction = date('Y-m-d');
$t->save();
$t_e->save();
$form->setValue('transaction_emetteur_id', $t_e);
$form->setValue('transaction_id', $t);
$form->setValue('asso_id', $asso->getPrimaryKey());
$avance_treso = $form->save();
$this->redirect('avances', $emetteur);
}
}
示例8: 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;
}
示例9: embedMergeForm
/**
* Embeds a form like "mergeForm" does, but will still
* save the input data.
*/
public function embedMergeForm($name, sfForm $form)
{
// This starts like sfForm::embedForm
$name = (string) $name;
if (true === $this->isBound() || true === $form->isBound()) {
throw new LogicException('A bound form cannot be merged');
}
$this->embeddedForms[$name] = $form;
$form = clone $form;
unset($form[self::$CSRFFieldName]);
// But now, copy each widget instead of the while form into the current
// form. Each widget ist named "formname|fieldname".
foreach ($form->getWidgetSchema()->getFields() as $field => $widget) {
$widgetName = "{$name}|{$field}";
if (isset($this->widgetSchema[$widgetName])) {
throw new LogicException("The forms cannot be merged. A field name ’{$widgetName’} already exists.");
}
$this->widgetSchema[$widgetName] = $widget;
// Copy widget
$this->validatorSchema[$widgetName] = $form->validatorSchema[$field];
// Copy schema
$this->setDefault($widgetName, $form->getDefault($field));
// Copy default value
if (!$widget->getLabel()) {
// Re-create label if not set (otherwise it would be named ’ucfirst($widgetName)’)
$label = $form->getWidgetSchema()->getFormFormatter()->generateLabelName($field);
$this->getWidgetSchema()->setLabel($widgetName, $label);
}
}
// And this is like in sfForm::embedForm
$this->resetFormFields();
}
示例10: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$isnew = $form->getObject()->isNew();
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
try {
$product = $form->save();
if ($product->getDescription() == "") {
$product->setDescription($product->getName());
$product->save();
}
} 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, ', ');
$this->getUser()->setFlash('error', $message);
return sfView::SUCCESS;
}
$this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $product)));
if ($request->hasParameter('_save_and_add')) {
$this->getUser()->setFlash('notice', $notice . ' You can add another one below.');
$this->redirect('@product_new');
} else {
$this->getUser()->setFlash('notice', $notice);
$this->redirect(array('sf_route' => 'product_edit', 'sf_subject' => $product));
}
} else {
$this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
}
}
示例11: getLanguage
private function getLanguage(sfForm $form)
{
$post = $form->getValues();
$language = $this->getEmployeeService()->getEmployeeLanguages($post['emp_number'], $post['code'], $post['lang_type']);
$isAllowed = FALSE;
if (!$language instanceof EmployeeLanguage) {
if ($this->languagePermissions->canCreate()) {
$language = new EmployeeLanguage();
$isAllowed = TRUE;
}
} else {
if ($this->languagePermissions->canUpdate()) {
$isAllowed = TRUE;
} else {
$this->getUser()->setFlash('warning', __("You don't have update permission"));
}
}
if ($isAllowed) {
$language->empNumber = $post['emp_number'];
$language->langId = $post['code'];
$language->fluency = $post['lang_type'];
$language->competency = $post['competency'];
$language->comments = $post['comments'];
return $language;
} else {
return NULL;
}
}
示例12: processForm
protected function processForm(sfWebRequest $request, sfForm $form)
{
$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
if ($form->isValid()) {
$contact_req = new ContactRequest();
$contact_req->setRequestDate(date('Y-m-d'));
$contact_req->setTitle($request->getParameter('contact_request[title]'));
$contact_req->setFirstName($request->getParameter('contact_request[first_name]'));
$contact_req->setLastName($request->getParameter('contact_request[last_name]'));
$contact_req->setAddress1($request->getParameter('contact_request[address1]'));
$contact_req->setAddress2($request->getParameter('contact_request[address2]'));
$contact_req->setCity($request->getParameter('contact_request[city]'));
$contact_req->setState($request->getParameter('contact_request[state]'));
$contact_req->setZipcode($request->getParameter('contact_request[zipcode]'));
$contact_req->setCountry($request->getParameter('contact_request[country]'));
$contact_req->setDayPhone($request->getParameter('contact_request[day_phone]'));
$contact_req->setEvePhone($request->getParameter('contact_request[eve_phone]'));
$contact_req->setFaxPhone($request->getParameter('contact_request[fax_phone]'));
$contact_req->setMobilePhone($request->getParameter('contact_request[mobile_phone]'));
$contact_req->setEmail($request->getParameter('contact_request[email]'));
$contact_req->setRefSourceId($request->getParameter('contact_request[ref_source_id]'));
$contact_req->setSendAppFormat($request->getParameter('contact_request[send_app_format]'));
$contact_req->setComment($request->getParameter('contact_request[comment]'));
//Set Session Id
$sessionId = session_id();
$contact_req->setSessionId($sessionId);
//end set session id
$contact_req->setIpAddress($request->getRemoteAddress());
$contact_req->save();
$this->redirect('contact_request/thankyou');
}
}
示例13: getEducation
private function getEducation(sfForm $form)
{
$post = $form->getValues();
$isAllowed = FALSE;
if (!empty($post['id'])) {
if ($this->educationPermissions->canUpdate()) {
$education = $this->getEmployeeService()->getEducation($post['id']);
$isAllowed = TRUE;
}
}
if (!$education instanceof EmployeeEducation) {
if ($this->educationPermissions->canCreate()) {
$education = new EmployeeEducation();
$isAllowed = TRUE;
}
}
if ($isAllowed) {
$education->empNumber = $post['emp_number'];
$education->educationId = $post['code'];
$education->institute = $post['institute'];
$education->major = $post['major'];
$education->year = $post['year'];
$education->score = $post['gpa'];
$education->startDate = $post['start_date'];
$education->endDate = $post['end_date'];
}
return $education;
}
示例14: getLicense
private function getLicense(sfForm $form)
{
$post = $form->getValues();
$license = $this->getEmployeeService()->getEmployeeLicences($post['emp_number'], $post['code']);
$isAllowed = FALSE;
if (!$license instanceof EmployeeLicense) {
if ($this->licensePermissions->canCreate()) {
$license = new EmployeeLicense();
$isAllowed = TRUE;
}
} else {
if ($this->licensePermissions->canUpdate()) {
$isAllowed = TRUE;
}
}
if ($isAllowed) {
$license->empNumber = $post['emp_number'];
$license->licenseId = $post['code'];
$license->licenseNo = $post['license_no'];
$license->licenseIssuedDate = $post['date'];
$license->licenseExpiryDate = $post['renewal_date'];
return $license;
} else {
return NULL;
}
}
示例15: setup
public static function setup(sfForm $form)
{
$formatter = new pmWidgetFormSchemaFormatterTable($form);
$form->getWidgetSchema()->addFormFormatter("pm_table", $formatter);
$form->getWidgetSchema()->setFormFormatterName("pm_table");
$form->unsetFields();
// auto configure widgets
pmWidgetFactory::replaceWidgets($form);
// auto configure validators
pmValidatorFactory::replaceValidators($form);
$form->configureWidgets();
$form->configureValidators();
if ($form instanceof pmFormPropel) {
$sf_user = sfContext::getInstance()->getUser();
if (method_exists($sf_user, "getGuardUser")) {
$user_id = $sf_user->getGuardUser()->getId();
if (array_key_exists("created_by", $form->getWidgetSchema()->getFields()) && $form->getObject()->isNew()) {
$form->getObject()->setCreatedBy($user_id);
}
if (array_key_exists("updated_by", $form->getWidgetSchema()->getFields())) {
$form->getObject()->setUpdatedBy($user_id);
}
}
}
}