<?php $form = \CPFCMembers\DataCapturePreferencesForm::getInstance(); $templateData = \CPFCMembers\TemplateData::getInstance(); ?> <section class="datacapture-panel"> <?php switch ($templateData->get('status')) { case 'SUCCESS': ?> <h1><?php the_field('data_capture_preferences_success_heading'); ?></h1> <?php the_field('data_capture_preferences_success_copy'); ?> <span id="datacapture-success" data-result="true"></span> <?php break; default: ?> <h1><?php the_field('data_capture_preferences_heading'); ?></h1> <?php the_field('data_capture_preferences_copy'); ?> <form class="datacapture" method="POST" action="<?php echo \CPFCMembers\Input::uri(); ?>"> <fieldset> <input type="hidden" name="details" value="preferences" /> <?php echo $form->securityField(); ?> <?php $form->displayError('form'); ?> <div class="form-block-wrap form-group"> <div class="check"> <input class="form-control" type="checkbox" name="preference_regular_newsletter" id="preference-regular-newsletter" value="1" <?php echo $form->getValue('preference_regular_newsletter') ? 'checked="checked"' : ''; ?> />
/** * Data Capture */ protected function _dataCapture() { $details = Input::request('details', false); $templateData = \CPFCMembers\TemplateData::getInstance(); $User = \CPFCMembers\Auth::getUser(); $template = ''; $status = ''; // Can't access if not logged in as Member if (\CPFCMembers\Auth::isLoggedIn()) { switch($details) { case 'address': $form = \CPFCMembers\DataCaptureAddressForm::getInstance(); $template = 'partials/data_capture/address_form'; break; case 'contact': $form = \CPFCMembers\DataCaptureContactForm::getInstance(); $template = 'partials/data_capture/contact_form'; break; case 'preferences': $form = \CPFCMembers\DataCapturePreferencesForm::getInstance(); $template = 'partials/data_capture/preferences_form'; break; case 'see_tickets': $form = \CPFCMembers\DataCaptureSeeTicketsForm::getInstance(); $template = 'partials/data_capture/see_tickets_form'; break; default: $status = 'INVALID_DETAIL'; $template = 'partials/data_capture/error'; $templateData->set('error_type', 'invalid_form_chosen'); } $notification = \CPFCMembers\MemberNotificationModel::loadByUserIdAndDetail($User->getId(), $details); if ($notification->getStatus() == 'complete') { $status = 'ALREADY_COMPLETED'; $template = 'partials/data_capture/error'; $templateData->set('error_type', 'already_completed'); } } else { $status = 'NOT_LOGGED_IN'; $template = 'partials/data_capture/error'; $templateData->set('error_type', 'not_logged_in'); } if ($status == '') { if (Input::isPost()) { $form->setValues(Input::post()); $form->validate(); if ($form->isValid()) { switch($details) { case 'address': $User->setHouseNameNumber(Input::post('house_name_number')); $User->setStreet(Input::post('street')); $User->setTown(Input::post('town')); $User->setCounty(Input::post('county')); $User->setPostcode(Input::post('postcode')); $User->setCountry(Input::post('country')); break; case 'contact': $User->setMobilePhone(Input::post('mobile_phone')); $User->setDaytimePhone(Input::post('daytime_phone')); break; case 'preferences': $User->setPreferenceRegularNewsletter(Input::post('preference_regular_newsletter')); $User->setPreferenceBreakingNews(Input::post('preference_breaking_news')); $User->setPreferencePartners(Input::post('preference_partners')); $User->setPreferenceSMS(Input::post('preference_sms')); break; case 'see_tickets': $User->setSeeTicketsAccountNumber(Input::post('see_tickets_account_number')); break; } if ($User->save(true)) { $status = 'SUCCESS'; $notification->setUserId($User->getId()) ->setDetail($details) ->setStatus('complete'); $notification->save(true); } else { $status = 'NOT_SAVED'; $template = 'partials/data_capture/error'; } } } else { $form->setValues($User->toArray(false, false)); } } $templateData->set('template', $template); $templateData->set('status', $status); $templateData->set('message', $message); }