/** * Generate a generic form * @param objForm $form * @param \Zend\Mvc\View\View $view * @param array $arr_options - Optional * @return string */ public function __invoke($objForm, $form, $view, $arr_options = NULL) { //assign view as class variable $this->view = $view; //populate form fields with values received in the query foreach ($_GET as $field => $value) { if ($form->has($field)) { $form->get($field)->setValue($value); } //end if } //end foreach //load form options if ($objForm->stylesheet != "") { //@TODO set path for uploaded files $view->headLink()->appendStylesheet($view->basePath() . "/css/frontcss/test_form_style.css"); } //end if //check if form top content is defined if ($objForm->copy != "" && is_string($objForm->copy)) { $html .= "<div class=\"container container_content_top form-content-top\">" . $objForm->copy . "</div>"; } //end if //load form show forward warning if ($objForm->show_fwd_warn == 1) { //$html .= "This form might be forwarded, click here to correct<br />"; } //end if //analyse options if (is_array($arr_options)) { //remove specified elements if (array_key_exists("arr_remove_elements", $arr_options)) { foreach ($arr_options["arr_remove_elements"] as $field) { if ($form->has($field) === TRUE) { $form->remove($field); } //end if } //end foreach } //end if if ($arr_options["generate_field_groups"] === TRUE) { $form_html = $this->generateFormWithFieldGroups($form, $view, $arr_options); //check if form has been generated if (!$form_html) { //generate normal form, grouped form could not be created } else { return $form_html; } //end if } //end if } //end if if ($form->hasAttribute("arr_field_groups") === TRUE) { $form->removeAttribute("arr_field_groups"); $form->remove("arr_field_groups"); } //end if if (!$html) { $html = ""; } //end if //set form attributes if (!$form->hasAttribute("class")) { $form->setAttribute("class", "form"); } //end class if (strtolower($form->getAttribute("id")) == "form") { $form->setAttribute("id", "form-id"); } //end if //check if form has style attributes if ($objForm->margins != "") { $form->setAttribute("style", "margin: " . $objForm->margins . ";"); } //end if //open the form tag $html .= $view->form()->openTag($form); //custom form element error structure $view->formElementErrors()->setMessageOpenFormat('<div class="bg-danger help-inline" style="padding: 10px; margin-top: 5px; margin-bottom: 5px;">')->setMessageSeparatorString('</div><div>')->setMessageCloseString('</div>'); //Added by Lodi $html .= "<div class=\"container container_form_fields\">"; foreach ($form as $form_element) { $html .= $this->generateFieldHtml($form, $form_element->getName()); } //end foreach //add submit button if ($form->has("submit")) { if ($form->get("submit")->getValue() == "") { if ($objForm->submit_button != "") { $form->get("submit")->setValue($objForm->submit_button); } else { $form->get("submit")->setValue("Submit"); } //end id } //end if $html .= "<div class=\"container container_submit\">"; $html .= $view->formSubmit($form->get("submit")); $html .= "</div>"; } //end if //Added by Lodi $html .= "</div>"; //close the form // $html .= $view->form()->closeTag(); //check if terms and conditions are defined if ($objForm->terms != "" && is_string($objForm->terms)) { $html .= "<div class=\"form-content-terms\">" . $objForm->terms . "</div>"; } //end if //check if form bottom content is defined if ($objForm->copy2 != "" && is_string($objForm->copy2)) { $html .= "<div class=\"form-content-bottom\">" . $objForm->copy2 . "</div>"; } //end if //close the form $html .= $view->form()->closeTag(); //Moved here by Lodi return $html; }