public function indexAction() { $this->layout('layout/myaccount'); $this->layout()->setVariable('mail_active', 'active'); $userTable = $this->getServiceLocator()->get('UserTable'); $allUsers = $userTable->fetchAll(); $usersList = array(); foreach ($allUsers as $user) { $usersList[$user->id] = $user->name . '(' . $user->email . ')'; } $user = $this->getLoggedInUser(); $request = $this->getRequest(); if ($request->isPost()) { $msgSubj = $request->getPost()->get('messageSubject'); $msgText = $request->getPost()->get('message'); $toUser = $request->getPost()->get('toUserId'); $fromUser = $user->id; $this->sendOfflineMessage($msgSubj, $msgText, $fromUser, $toUser); // to prevent duplicate entries on refresh return $this->redirect()->toRoute('users/mail', array('action' => 'sendOfflineMessage')); } //Prepare Send Message Form $form = new \Zend\Form\Form(); $form->setAttribute('method', 'post'); $form->setAttribute('enctype', 'multipart/form-data'); $form->add(array('name' => 'toUserId', 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('type' => 'select'), 'options' => array('label' => 'To User'))); $form->add(array('name' => 'messageSubject', 'attributes' => array('type' => 'text', 'id' => 'messageSubject', 'required' => 'required'), 'options' => array('label' => 'Subject'))); $form->add(array('name' => 'message', 'attributes' => array('type' => 'textarea', 'id' => 'message', 'required' => 'required'), 'options' => array('label' => 'Message'))); $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Send'), 'options' => array('label' => 'Send'))); $form->get('toUserId')->setValueOptions($usersList); $viewModel = new ViewModel(array('form' => $form, 'userName' => $user->name)); return $viewModel; }
public function indexAction() { $request = $this->getRequest(); if ($request->isPost()) { $queryText = $request->getPost()->get('query'); $searchIndexLocation = $this->getIndexLocation(); $index = Lucene\Lucene::open($searchIndexLocation); $searchResults = $index->find($queryText); // foreach ($searchResults as $searchResult) { // \Zend\Debug\Debug::dump($searchResult->upload_id); // } } // Подготовка формы поиска $form = new \Zend\Form\Form(); $form->add(array('name' => 'query', 'attributes' => array('type' => 'text', 'id' => 'queryText', 'required' => 'required'), 'options' => array('label' => 'Search String'))); $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Search'))); if ($request->isPost()) { $form->get('query')->setValue($request->getPost()->get('query')); } $viewModel = new ViewModel(array('form' => $form, 'searchResults' => $searchResults)); return $viewModel; }
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 $objUserStorage = FrontUserSession::getUserLocalStorageObject(); if (is_numeric($objUserStorage->readUserNativePreferences()->cpp_form_id)) { $form->get("cpp_form_id")->setValue($objUserStorage->readUserNativePreferences()->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 if (is_object($objUserStorage)) { $objUserStorage->setUserNativePreferences('cpp_form_id', $form_id); $objUserData->cookie_data->cpp_form_id = $form_id; } //end if } //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); }
/** * Create form to update Contact System Fields * @return \Zend\Form\Form */ public function getContactSystemFieldsForm() { //create form $form = new \Zend\Form\Form(); $form->setAttribute("id", 'system-fields-form'); $form->add(array("name" => "source_dropdown", "type" => "select", "attributes" => array("id" => "source_dropdown", "title" => "Set from existing Sources"), "options" => array("label" => "Select Source", "value_options" => array("test")))); $form->add(array("name" => "source", "type" => "text", "attributes" => array("id" => "source"), "options" => array("label" => "Source"))); $form->add(array("name" => "reference_dropdown", "type" => "select", "attributes" => array("id" => "reference_dropdown", "title" => "Set from existing References"), "options" => array("label" => "Select Reference", "value_options" => array("test")))); $form->add(array("name" => "reference", "type" => "text", "attributes" => array("id" => "reference"), "options" => array("label" => "Reference"))); $form->add(array("name" => "user_id", "type" => "select", "attributes" => array("id" => "user_id", "required" => "required"), "options" => array("label" => "User", "value_options" => array()))); $form->add(array("type" => "submit", "name" => "submit", "attributes" => array("value" => "Submit"))); /** * Populate Dropdowns */ //users $objUsers = $this->getFrontUsersModel()->fetchUsers(); $arr_users = array(); foreach ($objUsers as $objUser) { if (!is_numeric($objUser->id)) { continue; } //end if $arr_users[$objUser->id] = $objUser->uname; } //end foreach $form->get("user_id")->setValueOptions($arr_users); //sources $objSources = $this->getFrontContactsSystemFieldsModel()->fetchDistinctContactSources(); $arr_sources = array(); foreach ($objSources as $objSource) { $arr_sources[$objSource->source] = $objSource->source; } //end foreach $form->get("source_dropdown")->setValueOptions($arr_sources); //references $objReferences = $this->getFrontContactsSystemFieldsModel()->fetchDistinctContactReferences(); $arr_references = array(); foreach ($objReferences as $objRefence) { $arr_references[$objRefence->reference] = $objRefence->reference; } //end foreach $form->get("reference_dropdown")->setValueOptions($arr_references); return $form; }
<?php require_once './autoloader.php'; $form = new \Zend\Form\Form(); $form->add(array('name' => 'username', 'type' => 'Zend\\Form\\Element\\Text')); $subForm = new \Zend\Form\Form(); $subForm->setName('subform'); $subForm->add(array('name' => 'email', 'type' => 'Zend\\Form\\Element\\Text')); $form->add($subForm); $form->prepare(); $helper = new Zend\Form\View\Helper\FormText(); echo $helper($form->get('username')); echo $helper($form->get('subform')->get('email'));
/** * Submit a webform * @return Ambigous <\Zend\Http\Response, \Zend\Stdlib\ResponseInterface>|Ambigous <unknown, \Zend\Form\Form> */ public function bfAction() { //set container for additional params $arr_additional_params = array(); $form_id = $this->params()->fromRoute("fid"); $reg_id = $this->params()->fromRoute("reg_id", NULL); $arr_additional_params["reg_id"] = $reg_id; //check if reg id is encoded, if not, do not process if (is_numeric($reg_id)) { $this->flashMessenger()->addErrorMessage("An error occured attempting to load data"); //redirect back to form return $this->redirect()->toRoute("majestic-external-forms/bf", array("fid" => $form_id)); } //end if //load comm history id $comm_history_id = $this->params()->fromQuery("cid", ""); if ($comm_history_id != "") { $arr_additional_params["cid"] = $comm_history_id; } //end if //check form id has been set if (!is_string($form_id)) { echo "Form could not be loaded. Required information is not available."; exit; } //end if try { //load form details $arr_return = $this->getExternalFormsModel()->loadForm($form_id, $reg_id, $arr_additional_params); $arr_return["additional_data"] = $arr_additional_params; //add plain form url $arr_return["form_url"] = $this->url()->fromRoute("majestic-external-forms/bf", array("fid" => $form_id)); } catch (\Exception $e) { //@TODO do something with the error // var_dump($e->getMessage() . " : " . $e->getPrevious()); exit; die("The requested form could not be loaded. Response: " . $this->frontControllerErrorHelper()->formatErrors($e)); } //end catch if ($arr_return["objFormRawData"]->secure_form == "1") { if (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != "on" && $_SERVER["HTTPS"] != 1 && $_SERVER["SERVER_PORT"] != "443") { header("location:https://" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]); } //end if } //end if //should the user be logged in? if ($arr_return["objFormRawData"]->user_login == 1) { $objUserSession = FrontUserSession::isLoggedIn(); if (!$objUserSession) { $this->flashMessenger()->addInfoMessage("User must be logged in in order to access form"); //redirect to login screen return $this->redirect()->toRoute("front-user-login"); } //end if } //end if //should the contact be specified if ($arr_return["objFormRawData"]->id_required == 1 && $reg_id == "") { echo "Form could not be loaded. Contact ID is not set"; exit; } //end if //should the form be redirected on loading? if ($arr_return["objFormRawData"]->redirect_on_load != "") { header("location:" . $arr_return["objFormRawData"]->redirect_on_load); exit; } //end if //extract form from result $form = $arr_return["objForm"]; //does form have password access enabled? //@TODO set proper session data if ($arr_return["objFormRawData"]->form_password != "" && $_SESSION["form_data"]["password"] != $arr_return["objFormRawData"]->form_password) { $form = new \Zend\Form\Form(); $form->add(array("type" => "password", "name" => "password", "attributes" => array("id" => "password", "required" => "required"), "options" => array("label" => "Form Password"))); $form->add(array("type" => "submit", "name" => "submit", "attributes" => array("value" => "Submit"))); $request = $this->getRequest(); if ($request->isPost()) { if ($request->getPost("password") == $arr_return["objFormRawData"]->form_password) { $_SESSION["form_data"]["password"] = $request->getPost("password"); return $this->redirect()->toRoute("majestic-external-forms/bf", array("fid" => $form_id, "reg_id" => $reg_id)); } //end if } //end if if ($_SESSION["form_data"]["password"] != $arr_return["objFormRawData"]->form_password) { $arr_return["form"] = $form; return $arr_return; } //end if } //end if //is form captcha enabled? if ($arr_return["objFormRawData"]->captcha == 1) { if (!is_dir("./public/captcha")) { mkdir("./public/captcha", 0755, TRUE); } //end if $objCaptcha = new \Zend\Captcha\Image(array('expiration' => '300', 'wordlen' => '7', 'font' => 'data/fonts/arial.ttf', 'fontSize' => '20', 'imgDir' => 'public/captcha', 'imgUrl' => '/captcha', 'lineNoiseLevel' => 1, 'dotNoiseLevel' => 1)); $form->add(array("name" => "captcha", "type" => "Zend\\Form\\Element\\Captcha", "attributes" => array("id" => "captcha", "required" => "required", "autocomplete" => "off"), "options" => array("label" => "Human verification", "captcha" => $objCaptcha))); } //end if $arr_return["form_posted"] = FALSE; $request = $this->getRequest(); if ($request->isPost()) { if ($form->has("captcha")) { if (!$objCaptcha->isValid($request->getPost("captcha"), $request->getPost())) { $form->setData($request->getPost()); $this->flashMessenger()->addErrorMessage("CAPTCHA validation failed"); $arr_return["form"] = $form; return $arr_return; } //end if } //end if //set form post flag to stop javascript loading on form error $arr_return["form_posted"] = TRUE; $form->setData($request->getPost()); if ($form->isValid($request->getPost())) { try { //submit the form $objResult = $this->getExternalFormsModel()->processFormSubmit($form_id, $form->getData(), $arr_additional_params); //unset form password if (isset($_SESSION["form_data"]["password"])) { unset($_SESSION["form_data"]["password"]); } //end if //redirect to post submit page return $this->redirect()->toRoute("majestic-external-forms/bfs", array("fid" => $form_id, "reg_id" => $objResult->data->reg_id_encoded)); } catch (\Exception $e) { //extract errors from the request return by the API $arr_response = explode("||", $e->getMessage()); $objResponse = json_decode($arr_response[1]); //check if user is logged in to display links to duplicate contacts $objUserSession = FrontUserSession::isLoggedIn(); if (is_object($objResponse) && is_object($objUserSession)) { switch ($objResponse->HTTP_RESPONSE_CODE) { case 409: //duplicates found //extract message $arr_t = explode(":", $objResponse->HTTP_RESPONSE_MESSAGE); $id_string = array_pop($arr_t); $this->flashMessenger()->addErrorMessage(trim(str_replace(array("{", "}"), "", $id_string))); //extract ids and create links to each preg_match('~{(.*?)}~', $id_string, $output); $arr_contact_ids = explode(",", $output[1]); if (is_array($arr_contact_ids) && count($arr_contact_ids) > 0) { foreach ($arr_contact_ids as $k => $id) { $this->flashMessenger()->addInfoMessage("<a href=\"" . $this->url()->fromRoute("front-contacts", array("action" => "view-contact", "id" => $id)) . "\" target=\"_blank\" title=\"View Contact\">Click to view duplicate {$id}</a>"); if ($k > 19) { break; } //end if } //end foreach } //end if break; default: //add errors to the form already where set //@TODO this needs some work, messages should be generated back into the form directly... if (is_object($objResponse) && isset($objResponse->data)) { foreach ($objResponse->data as $k => $objField) { if (is_object($objField) && isset($objField->messages) && isset($objField->attributes->name)) { if ($form->has($objField->attributes->name)) { $arr_message = (array) $objField->messages; $form->get($objField->attributes->name)->setMessages($arr_message); $form->get($objField->attributes->name)->setValue($request->getPost($objField->attributes->name)); } //end if } //end if } //end if } //end if //set form errors $form = $this->frontFormHelper()->formatFormErrors($form, $e->getMessage()); break; } //end switch } else { //@TODO this needs some work, messages should be generated back into the form directly... if (is_object($objResponse) && isset($objResponse->data)) { foreach ($objResponse->data as $k => $objField) { if (is_object($objField) && isset($objField->messages) && isset($objField->attributes->name)) { if ($form->has($objField->attributes->name)) { $arr_message = (array) $objField->messages; $form->get($objField->attributes->name)->setMessages($arr_message); $form->get($objField->attributes->name)->setValue($request->getPost($objField->attributes->name)); } //end if } //end if } //end if } //end if //set form errors $form = $this->frontFormHelper()->formatFormErrors($form, $e->getMessage()); } //end if } //end catch } //end if } //end if $arr_return["form"] = $form; $arr_return["form_id"] = $form_id; if ($reg_id != "") { $arr_return["reg_id"] = $reg_id; } //end if return $arr_return; }
public function pickAddressesAction() { $userAddressService = $this->getServiceLocator()->get('SpeckUserAddress\\Service\\UserAddress'); $prg = $this->prg('checkout/user-information/addresses'); if ($prg instanceof Response) { return $prg; } $addresses = $userAddressService->getAddresses()->toArray(); $addressesArray = array(); foreach ($addresses as $a) { $addressesArray[$a['address_id']] = $a; } $shippingAddressForm = $this->getServiceLocator()->get('SpeckAddress\\Form\\Address'); $shippingAddressForm->setName('shipping')->setInputFilter($this->getServiceLocator()->get('SpeckAddress\\Form\\AddressFilter')); $billingAddressForm = $this->getServiceLocator()->get('SpeckAddress\\Form\\Address'); $billingAddressForm->setName('billing')->setInputFilter($this->getServiceLocator()->get('SpeckAddress\\Form\\AddressFilter')); $form = new \Zend\Form\Form(); $form->add($shippingAddressForm)->add($billingAddressForm); $checkoutService = $this->getServiceLocator()->get('SpeckCheckout\\Service\\Checkout'); if ($prg === false) { $strategy = $checkoutService->getCheckoutStrategy(); $return = array('addresses' => $addressesArray, 'form' => $form); if ($strategy->getShippingAddress()) { $return['ship_prefill'] = $strategy->getShippingAddress()->getAddressId(); } if ($strategy->getBillingAddress()) { $return['bill_prefill'] = $strategy->getBillingAddress()->getAddressId(); } return $return; } $shippingAddressId = isset($prg['shipping_address_id']) ? $prg['shipping_address_id'] : 0; $billingAddressId = isset($prg['billing_address_id']) ? $prg['billing_address_id'] : 0; $shipping = $form->get('shipping'); $billing = $form->get('billing'); $shipping->setData(isset($prg['shipping']) ? $prg['shipping'] : array()); $billing->setData(isset($prg['billing']) ? $prg['billing'] : array()); $valid1 = $shippingAddressId != 0 ? true : $shipping->isValid(); $valid2 = $billingAddressId != 0 ? true : $billing->isValid(); $valid = $valid1 && $valid2; if (!$valid) { return array('ship_prefill' => $shippingAddressId, 'bill_prefill' => $billingAddressId, 'addresses' => $addressesArray, 'form' => $form); } $addressService = $this->getServiceLocator()->get('SpeckAddress\\Service\\Address'); $userAddressService = $this->getServiceLocator()->get('SpeckUserAddress\\Service\\UserAddress'); $user = $this->zfcUserAuthentication()->getIdentity(); if ($shippingAddressId == 0) { $ship = $userAddressService->create($shipping->getData()); } else { $ship = $addressService->findById($shippingAddressId); } if ($billingAddressId == 0) { $bill = $userAddressService->create($billing->getData()); } else { $bill = $addressService->findById($billingAddressId); } $strategy = $checkoutService->getCheckoutStrategy(); $strategy->setShippingAddress($ship); $strategy->setBillingAddress($bill); $strategy->setEmailAddress($user->getEmail()); foreach ($strategy->getSteps() as $step) { if ($step instanceof UserInformation) { $step->setComplete(true); break; } } return $this->redirect()->toRoute('checkout'); }
<?php require_once './autoloader.php'; $form = new \Zend\Form\Form(); $select = array('name' => 'cat_id', 'type' => 'Zend\\Form\\Element\\Select', 'options' => array('label' => 'Categoria', 'value_options' => array('' => ''))); $form->add($select); $form->get('cat_id')->setValueOptions(array('foo' => 'bar')); $helper = new Zend\Form\View\Helper\FormSelect(); echo $helper($form->get('cat_id')); $formV = new \Zend\Form\Form(); $formV->add(array('name' => 'cat_id', 'type' => 'Zend\\Form\\Element\\Select', 'options' => array('label' => 'Categoria', 'value_options' => array('' => '')), 'require' => true, 'filters' => array(array('name' => 'Int')))); $formV->setData(array('cat_id' => 'bar')); $formV->prepare(); echo $formV->isValid();
<?php require_once './autoloader.php'; $form = new \Zend\Form\Form(); $form->add(array('name' => 'send', 'type' => 'Zend\\Form\\Element\\Image', 'attributes' => array('value' => 'Send', 'src' => 'abc.jpg'))); $helper = new Zend\Form\View\Helper\FormImage(); echo $helper($form->get('send'));