本文整理汇总了PHP中ContactForm::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP ContactForm::isValid方法的具体用法?PHP ContactForm::isValid怎么用?PHP ContactForm::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContactForm
的用法示例。
在下文中一共展示了ContactForm::isValid方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editAction
/** Edit staff profile
*/
public function editAction()
{
$form = new ContactForm();
$form->submit->setLabel('Save');
$form->removeElement('role');
$form->removeElement('alumni');
$form->removeElement('identifier');
$form->removeElement('role');
$form->removeElement('dbaseID');
$this->view->form = $form;
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$address = $form->getValue('address_1') . ',' . $form->getValue('address_2') . ',' . $form->getValue('town') . ',' . $form->getValue('county') . ',' . $form->getValue('postcode') . ', UK';
$coords = $this->_geocoder->getCoordinates($address);
if ($coords) {
$lat = $coords['lat'];
$long = $coords['lon'];
} else {
$lat = NULL;
$lon = NULL;
}
$woeid = $place->woeid;
$updateData = array('firstname' => $form->getValue('firstname'), 'lastname' => $form->getValue('lastname'), 'email_one' => $form->getValue('email_one'), 'email_two' => $form->getValue('email_two'), 'address_1' => $form->getValue('address_1'), 'address_2' => $form->getValue('address_2'), 'town' => $form->getValue('town'), 'county' => $form->getValue('county'), 'postcode' => $form->getValue('postcode'), 'telephone' => $form->getValue('telephone'), 'fax' => $form->getValue('fax'), 'region' => $form->getValue('region'), 'website' => $form->getValue('website'), 'profile' => $form->getValue('profile'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms(), 'latitude' => $lat, 'longitude' => $lon, 'woeid' => $woeid);
foreach ($updateData as $key => $value) {
if (is_null($value)) {
unset($updateData[$key]);
}
}
$contacts = new Contacts();
$where = array();
$where[] = $contacts->getAdapter()->quoteInto('dbaseID = ?', $this->getIdentityForForms());
$insert = $contacts->update($updateData, $where);
$this->_flashMessenger->addMessage('Contact information for ' . $form->getValue('firstname') . ' ' . $form->getValue('lastname') . ' updated!');
$this->_redirect('/users/account/');
} else {
$form->populate($formData);
}
} else {
$id = (int) $this->getIdentityForForms();
if ($id != 0) {
$contacts = new Contacts();
$contact = $contacts->fetchRow('dbaseID = ' . $id);
if (is_null($contact)) {
throw new Exception('Admin has not yet set up a profile for you');
} else {
$form->populate($contact->toArray());
}
}
}
}
示例2: contactAction
/**
* действие для странички с контактной формой - Contact
*
* @param Request $request
* @return int
*/
public function contactAction(Request $request)
{
$form = new ContactForm($request);
if ($request->isPost()) {
if ($form->isValid()) {
Session::setFlash('Message sent!');
header('Location: /contact');
die;
} else {
Session::setFlash('Fail');
}
}
$args = array('form' => $form);
return $this->render('contact', $args);
}
示例3: editAction
/** Edit staff profile
* @access public
* @return void
* @throws Pas_Exception_Param
*/
public function editAction()
{
$form = new ContactForm();
$form->submit->setLabel('Save');
$form->removeElement('role');
$form->removeElement('alumni');
$form->removeElement('identifier');
$form->removeElement('role');
$form->removeElement('dbaseID');
$this->view->form = $form;
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$address = $form->getValue('address_1') . ',' . $form->getValue('address_2') . ',' . $form->getValue('town') . ',' . $form->getValue('county') . ',' . $form->getValue('postcode') . ', UK';
$coords = $this->_geocoder->getCoordinates($address);
if ($coords) {
$lat = $coords['lat'];
$lon = $coords['lon'];
$pm = new Pas_Service_Geo_GeoPlanet($this->_helper->config()->webservice->ydnkeys->appid);
$place = $pm->reverseGeoCode($lat, $lon);
$woeid = $place['woeid'];
} else {
$lat = null;
$lon = null;
$woeid = null;
}
$updateData = $form->getValues();
$updateData['latitude'] = $lat;
$updateData['longitude'] = $lon;
$updateData['woeid'] = $woeid;
$where = array();
$where[] = $this->_contacts->getAdapter()->quoteInto('dbaseID = ?', $this->getIdentityForForms());
$this->_contacts->update($updateData, $where);
$this->getFlash()->addMessage('Contact information updated!');
$this->redirect('/users/account/');
} else {
$form->populate($formData);
}
} else {
$contact = $this->_contacts->fetchRow($this->_contacts->select()->where('dbaseID = ' . $this->getIdentityForForms()));
if (is_null($contact)) {
throw new Pas_Exception_Param('Admin has not yet set up a profile for you', 500);
} else {
$form->populate($contact->toArray());
}
}
}
示例4: sendAction
/**
* Saves the contact information in the database
*/
public function sendAction()
{
if ($this->request->isPost() != true) {
return $this->forward('contact/index');
}
$form = new ContactForm();
$contact = new Contact();
// Validate the form
$data = $this->request->getPost();
if (!$form->isValid($data, $contact)) {
foreach ($form->getMessages() as $message) {
$this->flash->error($message);
}
return $this->forward('contact/index');
}
if ($contact->save() == false) {
foreach ($contact->getMessages() as $message) {
$this->flash->error($message);
}
return $this->forward('contact/index');
}
$this->flash->success('Thanks, we will contact you in the next few hours');
return $this->forward('index/index');
}
示例5: executeContact
public function executeContact(sfWebRequest $request)
{
$route_params = $this->getRoute()->getParameters();
if (isset($route_params['type']) && $route_params['type'] == 'new') {
// CREATE
$target_list = $this->findTargetList();
/* @var $target_list MailingList */
if (!$target_list) {
return $this->notFound();
}
if (!$this->getGuardUser()->isTargetListMember($target_list, true)) {
return $this->noAccess();
}
$contact = new Contact();
$contact->setMailingList($target_list);
$route = 'target_contact_new';
$route_params = array('id' => $target_list->getId());
} else {
// EDIT
$contact = ContactTable::getInstance()->find($request->getParameter('id'));
/* @var $contact Contact */
if (!$contact) {
return $this->notFound();
}
$target_list = $contact->getMailingList();
if (!$this->getGuardUser()->isTargetListMember($target_list, true)) {
return $this->noAccess();
}
$route = 'target_contact';
$route_params = array('id' => $contact->getId(), 'page' => $request->getParameter('page'));
}
$form = new ContactForm($contact);
if ($request->isMethod('post')) {
$form->bind($request->getPostParameter($form->getName()));
if ($form->isValid()) {
$form->save();
$target_list->state(Doctrine_Record::STATE_DIRTY);
// to invalidate cache
$target_list->save();
$page = $request->getParameter('page');
if ($page) {
return $this->ajax()->replaceWithComponent('#contacts', 'target', 'contacts', array('target_list' => $target_list, 'page' => $page, 'no_filter' => true))->render();
} else {
return $this->ajax()->replaceWithComponent('#contacts', 'target', 'contacts', array('target_list' => $target_list, 'last_page' => true, 'no_filter' => true))->render();
}
} else {
return $this->ajax()->form($form)->render();
}
}
if (!$contact->isNew()) {
return $this->ajax()->remove('#contact_form_' . $contact->getId())->afterPartial('#contact_' . $contact->getId(), 'contact', array('form' => $form, 'route' => $route, 'route_params' => $route_params))->chosen('#contact_form_' . $contact->getId() . ' select', array('allow_single_deselect' => true))->render();
} else {
return $this->ajax()->remove('#contact_form_')->afterPartial('#contacts tbody', 'contact', array('form' => $form, 'route' => $route, 'route_params' => $route_params))->chosen('#contact_form_ select', array('allow_single_deselect' => true))->render();
}
}
示例6: editAction
/** Edit a contact's details
* @access public
* @return void
*/
public function editAction()
{
$form = new ContactForm();
$form->submit->setLabel('Save');
$this->view->form = $form;
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($this->_request->getPost())) {
$address = $form->getValue('address_1') . ',' . $form->getValue('address_2') . ',' . $form->getValue('town') . ',' . $form->getValue('county') . ',' . $form->getValue('postcode') . ', UK';
$coords = $this->getGeoCoder()->getCoordinates($address);
if ($coords) {
$lat = $coords['lat'];
$lon = $coords['lon'];
$place = $this->getGeoPlanet()->reverseGeoCode($lat, $lon);
$woeid = $place['woeid'];
} else {
$lat = null;
$lon = null;
$woeid = null;
}
$updateData = $form->getValues();
$updateData['latitude'] = $lat;
$updateData['longitude'] = $lon;
$updateData['woeid'] = $woeid;
$where = array();
$where[] = $this->getContacts()->getAdapter()->quoteInto('id = ?', $this->getParam('id'));
$this->getContacts()->update($updateData, $where);
$this->getFlash()->addMessage('Contact information updated!');
$this->redirect($this->_redirectUrl . 'contact/id/' . $this->getParam('id'));
} else {
$form->populate($this->_request->getPost());
}
} else {
$id = (int) $this->_request->getParam('id', 0);
if ($id > 0) {
$contact = $this->getContacts()->fetchRow('id=' . $id);
$form->populate($contact->toArray());
}
}
}
示例7: editAction
/** Edit a contact's details
*/
public function editAction()
{
$form = new ContactForm();
$form->submit->setLabel('Save');
$this->view->form = $form;
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($form->isValid($formData)) {
$address = $form->getValue('address_1') . ',' . $form->getValue('address_2') . ',' . $form->getValue('town') . ',' . $form->getValue('county') . ',' . $form->getValue('postcode') . ', UK';
$coords = $this->_geocoder->getCoordinates($address);
if ($coords) {
$lat = $coords['lat'];
$long = $coords['lon'];
$pm = new Pas_Service_Geoplanet();
$place = $pm->reverseGeoCode($lat, $lon);
$woeid = $place['woeid'];
} else {
$lat = NULL;
$lon = NULL;
$woeid = NULL;
}
$updateData = array('firstname' => $form->getValue('firstname'), 'lastname' => $form->getValue('lastname'), 'role' => $form->getValue('role'), 'dbaseID' => $form->getValue('dbaseID'), 'email_one' => $form->getValue('email_one'), 'email_two' => $form->getValue('email_two'), 'address_1' => $form->getValue('address_1'), 'address_2' => $form->getValue('address_2'), 'town' => $form->getValue('town'), 'county' => $form->getValue('county'), 'postcode' => $form->getValue('postcode'), 'identifier' => $form->getValue('identifier'), 'telephone' => $form->getValue('telephone'), 'fax' => $form->getValue('fax'), 'region' => $form->getValue('region'), 'website' => $form->getValue('website'), 'profile' => $form->getValue('profile'), 'alumni' => $form->getValue('alumni'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms(), 'latitude' => $lat, 'longitude' => $lon, 'woeid' => $woeid);
foreach ($updateData as $key => $value) {
if (is_null($value) || $value == "") {
unset($updateData[$key]);
}
}
$contacts = new Contacts();
$where = array();
$where[] = $contacts->getAdapter()->quoteInto('id = ?', $this->_getParam('id'));
$insert = $contacts->update($updateData, $where);
$this->_flashMessenger->addMessage('Contact information for ' . $form->getValue('firstname') . ' ' . $form->getValue('lastname') . ' updated!');
$this->_redirect($this->_redirectUrl . 'contact/id/' . $this->_getParam('id'));
} else {
$form->populate($formData);
}
} else {
$id = (int) $this->_request->getParam('id', 0);
if ($id > 0) {
$contacts = new Contacts();
$contact = $contacts->fetchRow('id=' . $id);
$form->populate($contact->toArray());
}
}
}