function saveNewsArticle($data, Form $form) { try { $form->clearMessage(); $form->resetValidation(); if ($data['newsID']) { $this->manager->updateNews($data); } else { $this->manager->postNews($data); } Session::clear("FormInfo.Form_NewsRequestForm.data"); return Controller::curr()->redirect('/news-add/?saved=1'); } catch (EntityValidationException $ex1) { $messages = $ex1->getMessages(); $msg = $messages[0]; $form->addErrorMessage('Headline', $msg['message'], 'bad'); SS_Log::log($msg['message'], SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_NewsRequestForm.data", $data); return $this->redirectBack(); } catch (Exception $ex) { $form->addErrorMessage('Headline', 'Server Error', 'bad'); SS_Log::log($ex->getMessage(), SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_NewsRequestForm.data", $data); return $this->redirectBack(); } }
function saveEventRegistrationRequest($data, Form $form) { // Check if the honeypot has been filled out if (@$data['username']) { SS_Log::log(sprintf('EventRegistrationRequestForm honeypot triggered (data: %s)', http_build_query($data)), SS_Log::NOTICE); return $this->httpError(403); } try { $this->event_registration_request_manager->registerEventRegistrationRequest($data); Session::clear("FormInfo.Form_EventRegistrationRequestForm.data"); $form->clearMessage(); return $this->redirect($this->Link('?saved=1')); } catch (EntityValidationException $ex1) { $messages = $ex1->getMessages(); $msg = $messages[0]; $form->addErrorMessage('City', $msg['message'], 'bad'); SS_Log::log($msg['message'], SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_EventRegistrationRequestForm.data", $data); return $this->redirectBack(); } catch (Exception $ex) { $form->addErrorMessage('Title', 'Server Error', 'bad'); SS_Log::log($ex->getMessage(), SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_EventRegistrationRequestForm.data", $data); return $this->redirectBack(); } }
public function Register($data, Form $form) { if (!Member::currentUser()) { $member = new Member(); // Debug::show($form); $form->saveInto($member); if (Group::get()->filter('Title', 'Subscribed')->count() == 0) { $group = Group::create(); $group->Title = 'Subscribed'; $group->write(); } else { $group = Group::get()->filter('Title', 'Subscribed')->First(); } if (Member::get()->filter('Email', $data['Email'])) { $form->addErrorMessage('Email', 'That email address is already in use. <a href="Security/login">login</a>', 'bad', true, true); //Controller::curr()->redirect('register'); } else { //has to be called before setting group $member->write(); if (!$member->inGroup($group)) { $member->Groups()->add($group); } } } Controller::curr()->redirectBack(); }
public function doSubmit(array $data, Form $form) { //basic spam protection if ($data['EmailMessage']) { $form->addErrorMessage('Message', 'We may have mistakenly marked your message as spam, please contact us via phone or email', 'warning'); Controller::curr()->redirectBack(); } if (!class_exists('FormSpamProtectionExtension')) { $time = time() - 20; if ($data['TimeLog'] <= $time) { $form->addErrorMessage('Message', 'We may have mistakenly marked your message as spam, please contact us via phone or email', 'warning'); Controller::curr()->redirectBack(); } } $siteConfig = SiteConfig::current_site_config(); if ($siteConfig->SiteEmail) { $From = $siteConfig->SiteEmail; } else { $From = $siteConfig->MainEmail; } $To = $siteConfig->SiteEmail; $Subject = "Website Contact From " . $data['Name']; $Body = $data['Company'] . "<br>\n " . $data['Email']; $email = new Email($From, $To, $Subject, $Body); $email->replyTo($data['Email']); $email->send(); $redirect = false; /* if($siteConfig->DefaultThankYouID != 0 && !$data['CustomThankYou']) { $redirect = ThankYouPage::get()->byID($siteConfig->DefaultThankYouID); } elseif ($data['CustomThankYou']) { $redirect = ThankYouPage::get()->byID($data['CustomThankYou']); } if($redirect){ Controller::curr()->redirect($redirect->URLSegment); } else { $form->addErrorMessage('Message', 'Thank you, someone from our office will contact you shortly', 'success'); Controller::curr()->redirectBack(); } */ $form->addErrorMessage('Message', 'Thank you, someone from our office will contact you shortly', 'success'); Controller::curr()->redirectBack(); }
/** * @param $data * @param Form $form * @return HTMLText * This is the function for calculate cost of plans based on input data, the cost data will add into original plan objects */ public function Calculate($data, Form $form) { Session::set('checkData', serialize($data)); $area = PlanCalculator::getArea($data['Suburb']); if ($area) { return $this->redirect('home/result'); } $form->addErrorMessage('Address', _t('Home.AddressInvalid', 'Sorry, your area is not supported yet.'), 'bad'); return $this->redirectBack(); }
function saveJobRegistrationRequest($data, Form $form) { try { $this->manager->registerJobRegistrationRequest($data); Session::clear("FormInfo.Form_JobRegistrationRequestForm.data"); return $this->redirect($this->Link('?saved=1')); } catch (EntityValidationException $ex1) { $messages = $ex1->getMessages(); $msg = $messages[0]; $form->addErrorMessage('Title', $msg['message'], 'bad'); SS_Log::log($msg['message'], SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_JobRegistrationRequestForm.data", $data); return $this->redirectBack(); } catch (Exception $ex) { $form->addErrorMessage('Title', 'Server Error', 'bad'); SS_Log::log($ex->getMessage(), SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_JobRegistrationRequestForm.data", $data); return $this->redirectBack(); } }
public function doInvite($data, Form $form) { $data = $form->getData(); $emails = $data['Emails']['new']; $sent = new DataObjectSet(); if (!$emails) { $form->addErrorMessage('Emails', 'Please enter at least one person to invite.'); } $time = DataObject::get_by_id('RegisterableDateTime', $data['TimeID']); $invite = new Email(); $invite->setSubject(sprintf('Event Invitation For %s (%s)', $time->EventTitle(), SiteConfig::current_site_config()->Title)); $invite->setTemplate('EventInvitationEmail'); $invite->populateTemplate(array('Time' => $time, 'SiteConfig' => SiteConfig::current_site_config(), 'Link' => Director::absoluteURL($time->Link()))); $count = count($emails['Name']); for ($i = 0; $i < $count; $i++) { $name = trim($emails['Name'][$i]); $email = trim($emails['Email'][$i]); if (!$name || !$email) { continue; } $regod = DataObject::get_one('EventRegistration', sprintf('"Email" = \'%s\' AND "TimeID" = \'%d\'', Convert::raw2sql($email), $time->ID)); if ($regod) { $sent->push(new ArrayData(array('Name' => $name, 'Email' => $email, 'Sent' => false, 'Reason' => 'Already registered'))); continue; } $invited = DataObject::get_one('EventInvitation', sprintf('"Email" = \'%s\' AND "TimeID" = \'%d\'', Convert::raw2sql($email), $time->ID)); if ($invited) { $sent->push(new ArrayData(array('Name' => $name, 'Email' => $email, 'Sent' => false, 'Reason' => 'Already invited'))); continue; } $invitation = new EventInvitation(); $invitation->Name = $name; $invitation->Email = $email; $invitation->TimeID = $time->ID; $invitation->EventID = $time->EventID; $invitation->write(); $_invite = clone $invite; $_invite->setTo($email); $_invite->populateTemplate(array('Name' => $name)); $_invite->send(); $sent->push(new ArrayData(array('Name' => $name, 'Email' => $email, 'Sent' => true))); } Requirements::clear(); $controller = $this->customise(array('Result' => $sent)); return $controller->renderWith('EventInvitationField_invite'); }
public function validateStep($data, Form $form) { Session::set("FormInfo.{$form->FormName()}.data", $form->getData()); $datetime = $this->getForm()->getController()->getDateTime(); $session = $this->getForm()->getSession(); $data = $form->getData(); $has = false; if ($datetime->Event()->OneRegPerEmail) { if (Member::currentUserID()) { $email = Member::currentUser()->Email; } else { $email = $data['Email']; } $existing = DataObject::get_one('EventRegistration', sprintf('"Email" = \'%s\' AND "Status" <> \'Canceled\' AND "TimeID" = %d', Convert::raw2sql($email), $datetime->ID)); if ($existing) { $form->addErrorMessage('Email', 'A registration for this email address already exists', 'required'); return false; } } // Ensure that the entered ticket data is valid. if (!$this->form->validateTickets($data['Tickets'], $form)) { return false; } // Finally add the tickets to the actual registration. $registration = $this->form->getSession()->getRegistration(); $hasLimit = (bool) $this->form->getController()->getDateTime()->Event()->RegistrationTimeLimit; if ($hasLimit && !$registration->isInDB()) { $registration->write(); } $total = $this->getTotal(); $registration->Total->setCurrency($total->getCurrency()); $registration->Total->setAmount($total->getAmount()); $registration->Name = $data['Name']; $registration->Email = $data['Email']; $registration->write(); $registration->Tickets()->removeAll(); foreach ($data['Tickets'] as $id => $quantity) { if ($quantity) { $registration->Tickets()->add($id, array('Quantity' => $quantity)); } } return true; }
public function postEntry(array $data, Form $form) { if (!empty($data['Website'])) { if (!filter_var($data['Website'], FILTER_VALIDATE_URL)) { $form->addErrorMessage('Website', _t('GuestbookController.INVALIDWEBSITEFORMAT', "Invalid format for website."), 'bad'); return $this->redirectBack(); } } if (Session::get("GuestbookPosted") > time() - $this->FloodLimit) { $floodMessage = _t('GuestbookController.FLOODLIMITEXCEEDED', "You have already posted the last {seconds} seconds. Please wait.", "", $this->FloodLimit); $form->sessionMessage($floodMessage, 'bad'); return $this->redirectBack(); } $entry = GuestbookEntry::create(); $entry->GuestbookID = $this->ID; $form->saveInto($entry); $entry->write(); $form->sessionMessage(_t('GuestbookController.ENTRYSAVED', "Entry has been saved."), 'good'); Session::set('GuestbookPosted', time()); return $this->redirectBack(); }
/** * Process the form that is submitted through the site * * @param array $data * @param Form $form * * @return Redirection */ public function process($data, $form) { Session::set("FormInfo.{$form->FormName()}.data", $data); Session::clear("FormInfo.{$form->FormName()}.errors"); foreach ($this->Fields() as $field) { $messages[$field->Name] = $field->getErrorMessage()->HTML(); $formField = $field->getFormField(); if ($field->Required && $field->CustomRules()->Count() == 0) { if (isset($data[$field->Name])) { $formField->setValue($data[$field->Name]); } if (!isset($data[$field->Name]) || !$data[$field->Name] || !$formField->validate($form->getValidator())) { $form->addErrorMessage($field->Name, $field->getErrorMessage(), 'bad'); } } } if (Session::get("FormInfo.{$form->FormName()}.errors")) { Controller::curr()->redirectBack(); return; } $submittedForm = Object::create('SubmittedForm'); $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0; $submittedForm->ParentID = $this->ID; // if saving is not disabled save now to generate the ID if (!$this->DisableSaveSubmissions) { $submittedForm->write(); } $values = array(); $attachments = array(); $submittedFields = new ArrayList(); foreach ($this->Fields() as $field) { if (!$field->showInReports()) { continue; } $submittedField = $field->getSubmittedFormField(); $submittedField->ParentID = $submittedForm->ID; $submittedField->Name = $field->Name; $submittedField->Title = $field->getField('Title'); // save the value from the data if ($field->hasMethod('getValueFromData')) { $submittedField->Value = $field->getValueFromData($data); } else { if (isset($data[$field->Name])) { $submittedField->Value = $data[$field->Name]; } } if (!empty($data[$field->Name])) { if (in_array("EditableFileField", $field->getClassAncestry())) { if (isset($_FILES[$field->Name])) { $foldername = $field->getFormField()->getFolderName(); // create the file from post data $upload = new Upload(); $file = new File(); $file->ShowInSearch = 0; try { $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername); } catch (ValidationException $e) { $validationResult = $e->getResult(); $form->addErrorMessage($field->Name, $validationResult->message(), 'bad'); Controller::curr()->redirectBack(); return; } // write file to form field $submittedField->UploadedFileID = $file->ID; // attach a file only if lower than 1MB if ($file->getAbsoluteSize() < 1024 * 1024 * 1) { $attachments[] = $file; } } } } $submittedField->extend('onPopulationFromField', $field); if (!$this->DisableSaveSubmissions) { $submittedField->write(); } $submittedFields->push($submittedField); } $emailData = array("Sender" => Member::currentUser(), "Fields" => $submittedFields); $this->extend('updateEmailData', $emailData, $attachments); // email users on submit. if ($recipients = $this->FilteredEmailRecipients($data, $form)) { $email = new UserDefinedForm_SubmittedFormEmail($submittedFields); $mergeFields = $this->getMergeFieldsMap($emailData['Fields']); if ($attachments) { foreach ($attachments as $file) { if ($file->ID != 0) { $email->attachFile($file->Filename, $file->Filename, HTTP::get_mime_type($file->Filename)); } } } foreach ($recipients as $recipient) { $parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields); if (!$recipient->SendPlain && $recipient->emailTemplateExists()) { $email->setTemplate($recipient->EmailTemplate); } $email->populateTemplate($recipient); $email->populateTemplate($emailData); $email->setFrom($recipient->EmailFrom); $email->setBody($parsedBody); $email->setTo($recipient->EmailAddress); $email->setSubject($recipient->EmailSubject); if ($recipient->EmailReplyTo) { $email->setReplyTo($recipient->EmailReplyTo); } // check to see if they are a dynamic reply to. eg based on a email field a user selected if ($recipient->SendEmailFromField()) { $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name); if ($submittedFormField && is_string($submittedFormField->Value)) { $email->setReplyTo($submittedFormField->Value); } } // check to see if they are a dynamic reciever eg based on a dropdown field a user selected if ($recipient->SendEmailToField()) { $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name); if ($submittedFormField && is_string($submittedFormField->Value)) { $email->setTo($submittedFormField->Value); } } // check to see if there is a dynamic subject if ($recipient->SendEmailSubjectField()) { $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name); if ($submittedFormField && trim($submittedFormField->Value)) { $email->setSubject($submittedFormField->Value); } } $this->extend('updateEmail', $email, $recipient, $emailData); if ($recipient->SendPlain) { $body = strip_tags($recipient->getEmailBodyContent()) . "\n"; if (isset($emailData['Fields']) && !$recipient->HideFormData) { foreach ($emailData['Fields'] as $Field) { $body .= $Field->Title . ': ' . $Field->Value . " \n"; } } $email->setBody($body); $email->sendPlain(); } else { $email->send(); } } } $submittedForm->extend('updateAfterProcess'); Session::clear("FormInfo.{$form->FormName()}.errors"); Session::clear("FormInfo.{$form->FormName()}.data"); $referrer = isset($data['Referrer']) ? '?referrer=' . urlencode($data['Referrer']) : ""; // set a session variable from the security ID to stop people accessing // the finished method directly. if (!$this->DisableAuthenicatedFinishAction) { if (isset($data['SecurityID'])) { Session::set('FormProcessed', $data['SecurityID']); } else { // if the form has had tokens disabled we still need to set FormProcessed // to allow us to get through the finshed method if (!$this->Form()->getSecurityToken()->isEnabled()) { $randNum = rand(1, 1000); $randHash = md5($randNum); Session::set('FormProcessed', $randHash); Session::set('FormProcessedNum', $randNum); } } } if (!$this->DisableSaveSubmissions) { Session::set('userformssubmission' . $this->ID, $submittedForm->ID); } return $this->redirect($this->Link('finished') . $referrer . $this->config()->finished_anchor); }
/** * Using custom validateField method * as Spam Protection Field implementations may have their own error messages * and may not be based on the field being required, e.g. Honeypot Field * * @param array $data * @param Form $form * @return void */ public function validateField($data, $form) { $formField = $this->getFormField(); if (isset($data[$this->Name])) { $formField->setValue($data[$this->Name]); } $validator = $form->getValidator(); if (!$formField->validate($validator)) { $errors = $validator->getErrors(); $foundError = false; // field validate implementation may not add error to validator if (count($errors) > 0) { // check if error already added from fields' validate method foreach ($errors as $error) { if ($error['fieldName'] == $this->Name) { $foundError = $error; break; } } } if ($foundError !== false) { // use error messaging already set from validate method $form->addErrorMessage($this->Name, $foundError['message'], $foundError['messageType'], false); } else { // fallback to custom message set in CMS or default message if none set $form->addErrorMessage($this->Name, $this->getErrorMessage()->HTML(), 'error', false); } } }
function submit(array $data, Form $form, $message = "Order updated", $status = "good") { if (isset($data['DiscountCouponCode'])) { $order = ShoppingCart::current_order(); if ($order) { $modifiers = $order->Modifiers('DiscountCouponModifier'); $modifier = $modifiers->First(); if ($modifier) { list($message, $type) = $modifier->updateCouponCodeEntered(Convert::raw2sql($data['DiscountCouponCode'])); $form->addErrorMessage("DiscountCouponCode", $message, $type); return ShoppingCart::singleton()->setMessageAndReturn($message, $type); } } } return ShoppingCart::singleton()->setMessageAndReturn(_t("DiscountCouponModifier.NOTAPPLIED", "Coupon could not be found.", "bad")); }
/** * Validates that the tickets requested are available and valid. * * @param array $tickets A map of ticket ID to quantity. * @param Form $form * @return bool */ public function validateTickets($tickets, $form) { $datetime = $this->controller->getDateTime(); $session = $this->getSession(); // First check we have at least one ticket. if (!array_sum($tickets)) { $form->addErrorMessage('Tickets', 'Please select at least one ticket to purchase.', 'required'); return false; } // Loop through each ticket and check that the data entered is valid // and they are available. foreach ($tickets as $id => $quantity) { if (!$quantity) { continue; } if (!is_int($quantity) && !ctype_digit($quantity)) { $form->addErrorMessage('Tickets', 'Please only enter numerical amounts for ticket quantities.', 'required'); return false; } $ticket = $datetime->Tickets('"EventTicket"."ID" = ' . (int) $id); if (!($ticket = $ticket->First())) { $form->addErrorMessage('Tickets', 'An invalid ticket ID was entered.', 'required'); return false; } $avail = $ticket->getAvailableForDateTime($datetime, $session->RegistrationID); $avail = $avail['available']; if (!$avail) { $form->addErrorMessage('Tickets', sprintf('%s is currently not available.', $ticket->Title), 'required'); return false; } if (is_int($avail) && $avail < $quantity) { $form->addErrorMessage('Tickets', sprintf('There are only %d of "%s" available.', $avail, $ticket->Title), 'required'); return false; } if ($ticket->MinTickets && $quantity < $ticket->MinTickets) { $form->addErrorMessage('Tickets', sprintf('You must purchase at least %d of "%s".', $ticket->MinTickets, $ticket->Title), 'required'); return false; } if ($ticket->MaxTickets && $quantity > $ticket->MaxTickets) { $form->addErrorMessage('Tickets', sprintf('You can only purchase at most %d of "%s".', $ticket->MaxTickets, $ticket->Title), 'required'); return false; } } // Then check the sum of the quantities does not exceed the overall // event capacity. if ($datetime->Capacity) { $avail = $datetime->getRemainingCapacity($session->RegistrationID); $request = array_sum($tickets); if ($request > $avail) { $message = sprintf('The event only has %d overall places remaining, but you ' . 'have requested a total of %d places. Please select a ' . 'lower number.', $avail, $request); $form->addErrorMessage('Tickets', $message, 'required'); return false; } } return true; }
/** * Process the form that is submitted through the site. Note that omnipay fields are NOT saved to the database. * This is intentional (so we don't save credit card details) but should be fixed in future, so we save all fields, * but only save the last 3 digits of the credit card (and not the CVV/exp date) * * @todo: save all fields to database except credit card fields * * @param array $data * @param Form $form * * @return Redirection */ public function process($data, $form) { Session::set("FormInfo.{$form->FormName()}.data", $data); Session::clear("FormInfo.{$form->FormName()}.errors"); foreach ($this->Fields() as $field) { $messages[$field->Name] = $field->getErrorMessage()->HTML(); $formField = $field->getFormField(); if ($field->Required && $field->CustomRules()->Count() == 0) { if (isset($data[$field->Name])) { $formField->setValue($data[$field->Name]); } if (!isset($data[$field->Name]) || !$data[$field->Name] || !$formField->validate($form->getValidator())) { $form->addErrorMessage($field->Name, $field->getErrorMessage(), 'bad'); } } } if (Session::get("FormInfo.{$form->FormName()}.errors")) { Controller::curr()->redirectBack(); return; } // if there are no errors, create the payment $submittedForm = Object::create('SubmittedPaymentForm'); $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0; $submittedForm->ParentID = $this->ID; // if saving is not disabled save now to generate the ID if (!$this->DisableSaveSubmissions) { $submittedForm->write(); } $attachments = array(); $submittedFields = new ArrayList(); foreach ($this->Fields() as $field) { if (!$field->showInReports()) { continue; } $submittedField = $field->getSubmittedFormField(); $submittedField->ParentID = $submittedForm->ID; $submittedField->Name = $field->Name; $submittedField->Title = $field->getField('Title'); // save the value from the data if ($field->hasMethod('getValueFromData')) { $submittedField->Value = $field->getValueFromData($data); } else { if (isset($data[$field->Name])) { $submittedField->Value = $data[$field->Name]; } } if (!empty($data[$field->Name])) { if (in_array("EditableFileField", $field->getClassAncestry())) { if (isset($_FILES[$field->Name])) { $foldername = $field->getFormField()->getFolderName(); // create the file from post data $upload = new Upload(); $file = new File(); $file->ShowInSearch = 0; try { $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername); } catch (ValidationException $e) { $validationResult = $e->getResult(); $form->addErrorMessage($field->Name, $validationResult->message(), 'bad'); Controller::curr()->redirectBack(); return; } // write file to form field $submittedField->UploadedFileID = $file->ID; // attach a file only if lower than 1MB if ($file->getAbsoluteSize() < 1024 * 1024 * 1) { $attachments[] = $file; } } } } $submittedField->extend('onPopulationFromField', $field); if (!$this->DisableSaveSubmissions) { $submittedField->write(); } $submittedFields->push($submittedField); } /** Do the payment **/ // move this up here for our redirect link $referrer = isset($data['Referrer']) ? '?referrer=' . urlencode($data['Referrer']) : ""; // set amount $currency = $this->data()->PaymentCurrency; $paymentfieldname = $this->PaymentAmountField()->Name; $amount = $data[$paymentfieldname]; $postdata = $data; // request payment $payment = Payment::create()->init($this->data()->PaymentGateway, $amount, $currency); $payment->write(); $response = PurchaseService::create($payment)->setReturnUrl($this->Link('finished') . $referrer)->setCancelUrl($this->Link('finished') . $referrer)->purchase($postdata); // save payment to order $submittedForm->PaymentID = $payment->ID; $submittedForm->write(); $emailData = array("Sender" => Member::currentUser(), "Fields" => $submittedFields); $this->extend('updateEmailData', $emailData, $attachments); $submittedForm->extend('updateAfterProcess'); Session::clear("FormInfo.{$form->FormName()}.errors"); Session::clear("FormInfo.{$form->FormName()}.data"); // set a session variable from the security ID to stop people accessing the finished method directly if (isset($data['SecurityID'])) { Session::set('FormProcessed', $data['SecurityID']); } else { // if the form has had tokens disabled we still need to set FormProcessed // to allow us to get through the finshed method if (!$this->Form()->getSecurityToken()->isEnabled()) { $randNum = rand(1, 1000); $randHash = md5($randNum); Session::set('FormProcessed', $randHash); Session::set('FormProcessedNum', $randNum); } } if (!$this->DisableSaveSubmissions) { Session::set('userformssubmission' . $this->ID, $submittedForm->ID); } return $response->redirect(); }
/** * Handles the form submission for the speaker "Update my details" page * @param array $data * @param Form $form * @return [type] [description] */ public function doReviewForm($data, $form) { Session::set("FormInfo.{$form->FormName()}.data", $data); if (empty(strip_tags($data['Bio']))) { $form->addErrorMessage('Bio', 'Please enter a bio', 'bad'); return $this->redirectBack(); } $form->saveInto($this->speaker); $this->speaker->Member()->setSummitState('BUREAU_SEEEN'); if ($data['VideoAgreement'] == 1) { $this->speaker->Member()->setSummitState('VIDEO_AGREEMENT_AGREED', $this->parent->getParent()->LegalAgreement); } else { $this->speaker->Member()->setSummitState('VIDEO_AGREEMENT_DECLINED'); } $this->speaker->write(); $form->sessionMessage('Your details have been updated.', 'good'); Session::clear("FormInfo.{$form->FormName()}.data", $data); return $this->parent->getParent()->redirectBack(); }
/** * Register a new member * * @param array $data User submitted data * @param Form $form The used form */ function doregister($data, $form) { // Check if the honeypot has been filled out if (ForumHolder::$use_honeypot_on_register) { if (@$data['username']) { SS_Log::log(sprintf('Forum honeypot triggered (data: %s)', http_build_query($data)), SS_Log::NOTICE); return $this->httpError(403); } } $forumGroup = DataObject::get_one('Group', "\"Code\" = 'forum-members'"); if ($member = DataObject::get_one("Member", "\"Email\" = '" . Convert::raw2sql($data['Email']) . "'")) { if ($member) { $form->addErrorMessage("Blurb", _t('ForumMemberProfile.EMAILEXISTS', 'Sorry, that email address already exists. Please choose another.'), "bad"); // Load errors into session and post back Session::set("FormInfo.Form_RegistrationForm.data", $data); Director::redirectBack(); return; } } elseif ($this->getForumHolder()->OpenIDAvailable() && isset($data['IdentityURL']) && ($member = DataObject::get_one("Member", "\"IdentityURL\" = '" . Convert::raw2sql($data['IdentityURL']) . "'"))) { if ($member) { $form->addErrorMessage("Blurb", _t('ForumMemberProfile.OPENIDEXISTS', 'Sorry, that OpenID is already registered. Please choose another or register without OpenID.'), "bad"); // Load errors into session and post back Session::set("FormInfo.Form_RegistrationForm.data", $data); Director::redirectBack(); return; } } elseif ($member = DataObject::get_one("Member", "\"Nickname\" = '" . Convert::raw2sql($data['Nickname']) . "'")) { if ($member) { $form->addErrorMessage("Blurb", _t('ForumMemberProfile.NICKNAMEEXISTS', 'Sorry, that nickname already exists. Please choose another.'), "bad"); // Load errors into session and post back Session::set("FormInfo.Form_RegistrationForm.data", $data); Director::redirectBack(); return; } } // create the new member $member = Object::create('Member'); $form->saveInto($member); $member->write(); $member->login(); $forumGroup->Members()->add($member); if (isset($data['BackURL']) && $data['BackURL']) { return Director::redirect($data['BackURL']); } return array("Form" => DataObject::get_one("ForumHolder")->ProfileAdd); }
/** * Register a new member. This action is deigned to be intercepted at 2 * points: * * - Modify the initial member filter (so that you can perfom bespoke * member filtering * * - Modify the member user before saving (so we can add extra permissions * etc) * * @param array $data User submitted data * @param Form $form Registration form */ public function doRegister($data, $form) { $filter = array(); if (isset($data['Email'])) { $filter['Email'] = $data['Email']; } $this->extend("updateMemberFilter", $filter); // Check if a user already exists if ($member = Member::get()->filter($filter)->first()) { if ($member) { $form->addErrorMessage("Blurb", "Sorry, an account already exists with those details.", "bad"); // Load errors into session and post back unset($data["Password"]); Session::set("Form.{$form->FormName()}.data", $data); return $this->redirectBack(); } } $member = Member::create(); $form->saveInto($member); // Set verification code for this user $member->VerificationCode = sha1(mt_rand() . mt_rand()); $member->write(); $this->extend("updateNewMember", $member, $data); // Add member to any groups that have been specified if (count(Users::config()->new_user_groups)) { $groups = Group::get()->filter(array("Code" => Users::config()->new_user_groups)); foreach ($groups as $group) { $group->Members()->add($member); $group->write(); } } // Send a verification email, if needed if (Users::config()->send_verification_email) { $sent = $this->send_verification_email($member); } else { $sent = false; } // Login (if enabled) if (Users::config()->login_after_register) { $member->LogIn(isset($data['Remember'])); } // If a back URL is used in session. if (Session::get("BackURL")) { $redirect_url = Session::get("BackURL"); } else { $redirect_url = Controller::join_links(BASE_URL, Users_Account_Controller::config()->url_segment); } return $this->redirect($redirect_url); }