public function userNativePreferencesAction()
 {
     //check if user is already logged in, if so, redirect to the home page
     if (FrontUserSession::isLoggedIn() === FALSE) {
         return $this->redirect()->toRoute("home");
     }
     //end if
     //set layout
     $this->layout("layout/layout");
     //check if local storage has been enabled
     $arr_config = $this->getServiceLocator()->get("config");
     if (!isset($arr_config["logged_in_user_settings"])) {
         $storage_disabled = TRUE;
     } elseif (isset($arr_config["logged_in_user_settings"]) && $arr_config["logged_in_user_settings"]["storage_enabled"] !== TRUE) {
         $storage_disabled = TRUE;
     }
     //end if
     if (isset($storage_disabled)) {
         $this->flashMessenger()->addInfoMessage("User preferences cannot be saved. Service is not enabled");
         return $this->redirect()->toRoute("home");
     }
     //end if
     //load form
     $form = $this->getUserLoginModel()->getUserNativePreferencesForm($this);
     //load user preferences
     $objUserData = FrontUserSession::readUserLocalData('cookie_data');
     foreach ($objUserData->cookie_data as $key => $value) {
         if ($form->has($key)) {
             $form->get($key)->setValue($value);
         }
         //end if
     }
     //end foreach
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             try {
                 $arr_data = (array) $form->getData();
                 foreach ($arr_data as $key => $value) {
                     $objUserData->cookie_data->{$key} = $value;
                 }
                 //end foreach
                 //save the data
                 FrontUserSession::saveUserLocalData("cookie_data", $objUserData->cookie_data);
                 $this->flashMessenger()->addSuccessMessage("Preferences saved");
             } catch (\Exception $e) {
                 $this->flashMessenger()->addErrorMessage($e->getMessage);
             }
             //end catch
         }
         //end if
     }
     //end if
     return array("form" => $form);
 }
 public function selectProfileFormAction()
 {
     $request = $this->getRequest();
     $form = new \Zend\Form\Form();
     $redirect = $this->params()->fromQuery("redirect", "");
     //load contact profile forms
     $arr_forms = $this->getContactsModel()->getContactProfileForm();
     //create radio button options
     foreach ($arr_forms as $key => $form_name) {
         $arr_element_value_options[$key] = $form_name;
     }
     //end foreach
     //add radio group to form
     $form->add(array("type" => "radio", "name" => "cpp_form_id", "options" => array("label" => "Please select the form you would like to use:", "value_options" => $arr_element_value_options)));
     //add remember option radio button
     $form->add(array('type' => 'checkbox', 'name' => 'remember_form', 'options' => array('label' => 'Remember my option', 'use_hidden_element' => true, 'checked_value' => '1', 'unchecked_value' => '0')));
     $form->add(array("name" => "submit", "attributes" => array("value" => "Submit"), "options" => array("ignore" => TRUE)));
     //check if local storage has been enabled
     $arr_config = $this->getServiceLocator()->get("config");
     if (!isset($arr_config["logged_in_user_settings"])) {
         $storage_disabled = TRUE;
     } elseif (isset($arr_config["logged_in_user_settings"]) && $arr_config["logged_in_user_settings"]["storage_enabled"] !== TRUE) {
         $storage_disabled = TRUE;
     }
     //end if
     if (isset($storage_disabled)) {
         $form->remove("remember_form");
     }
     //end if
     //load user session data
     $objUserSession = FrontUserSession::readUserLocalData("cookie_data");
     if (is_numeric($objUserSession->cookie_data->cpp_form_id)) {
         $form->get("cpp_form_id")->setValue($objUserSession->cookie_data->cpp_form_id);
     }
     //end if
     if ($request->isPost()) {
         //validate form submitted
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $arr_form_data = $form->getData();
             $form_id = $arr_form_data["cpp_form_id"];
             if (isset($arr_form_data["remember_form"]) && $arr_form_data["remember_form"] == 1) {
                 //persist user preference
                 $objUserData = FrontUserSession::readUserLocalData("cookie_data");
                 if (is_object($objUserData) && isset($objUserData->cookie_data)) {
                     $objUserData->cookie_data->cpp_form_id = $form_id;
                 } else {
                     $objUserData = new \stdClass();
                     $objUserData->cookie_data = (object) array('cpp_form_id' => $form_id);
                 }
                 //end if
                 FrontUserSession::saveUserLocalData("cookie_data", $objUserData->cookie_data);
             }
             //end if
             //check if redirect has been specified
             if ($redirect != "") {
                 //redirect received
                 return $this->redirect()->toUrl($redirect . "?fid={$form_id}");
             }
             //end if
             //redirect back to the contact edit screen with form id specified
             $url = $this->url()->fromRoute("front-contacts", array("action" => "create-contact"));
             //execute redirect
             $response = $this->getResponse();
             $response->getHeaders()->addHeaderLine('Location', $url . "?fid={$form_id}");
             $response->setStatusCode(302);
             return $response;
         }
         //end if
     }
     //end if
     return array("form" => $form, "redirect" => $redirect);
 }