From c2731333b94c302b8ab5623a348d8857e3e54e4b Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 12 Dec 2014 09:03:33 -0500 Subject: [PATCH] Clean up how to pull in the setting files and thier location starts with form 1 using settings1.php and so on... --- .../settings.php => config/settings1.php | 0 {models/forms => config}/settings2.php | 0 {models/forms => config}/settings3.php | 0 {models/forms => config}/settings4.php | 0 controllers/front.php | 65 +++++++------------ 5 files changed, 23 insertions(+), 42 deletions(-) rename models/forms/settings.php => config/settings1.php (100%) rename {models/forms => config}/settings2.php (100%) rename {models/forms => config}/settings3.php (100%) rename {models/forms => config}/settings4.php (100%) diff --git a/models/forms/settings.php b/config/settings1.php similarity index 100% rename from models/forms/settings.php rename to config/settings1.php diff --git a/models/forms/settings2.php b/config/settings2.php similarity index 100% rename from models/forms/settings2.php rename to config/settings2.php diff --git a/models/forms/settings3.php b/config/settings3.php similarity index 100% rename from models/forms/settings3.php rename to config/settings3.php diff --git a/models/forms/settings4.php b/config/settings4.php similarity index 100% rename from models/forms/settings4.php rename to config/settings4.php diff --git a/controllers/front.php b/controllers/front.php index 3a76951..7d715fe 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -9,6 +9,7 @@ defined('ABSPATH') or die(); */ class glm_employment_front { + // class properties public $pluginDirName; public $formSuccess; public $formFail; @@ -24,7 +25,9 @@ class glm_employment_front public $appId; public $formId; - const FORM_VAR = 'applyOnline'; + // class constants + const FORM_VAR = 'applyOnline'; + const FORM_SETTINGS_DIR = 'config'; /** * Register Hooks and Actions @@ -65,9 +68,16 @@ class glm_employment_front } } + public function load_form_settings($form_part = '') + { + $setting_file = $this->pluginDirName . self::FORM_SETTINGS_DIR + . "/settings{$form_part}.php"; + include $setting_file; + return (is_array($form)) ? $form : array(); + } + public function show_apply_form() { -// echo '
'.print_r($_REQUEST, true).'
'; $formPart = (isset($_REQUEST['form_part'])) ? filter_var($_REQUEST['form_part'], FILTER_VALIDATE_INT) : false; @@ -76,14 +86,14 @@ class glm_employment_front switch ($formPart) { default: unset($_SESSION['glmJobsApplication'], $_SESSION['glmJobsAppForm']); - include $this->pluginDirName . 'models/forms/settings.php'; + $form = $this->load_form_settings(1); $formPart = 1; include $this->pluginDirName . 'views/front/form_1.php'; break; case 1: if ($this->formSubmitted) { - include $this->pluginDirName . 'models/forms/settings.php'; + $form = $this->load_form_settings(1); $this->form_process($form, 1); $this->appId = $appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT); if (!$appId) { @@ -103,7 +113,7 @@ class glm_employment_front // next form part $formPart = 2; $appId = $this->appId; - include $this->pluginDirName . 'models/forms/settings2.php'; + $form = $this->load_form_settings(2); include $this->pluginDirName . 'views/front/form_1.php'; } } else { @@ -112,41 +122,21 @@ class glm_employment_front break; case 2: - if ($this->formSubmitted) { - include $this->pluginDirName . 'models/forms/settings2.php'; - $this->form_process($form, 2); - - $this->appId = $appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT); - - if ($this->errorCount > 0) { - include $this->pluginDirName . 'views/front/form_1.php'; - } else { - $this->store_form_data($form, 2); - // next form part - $formPart = 3; - include $this->pluginDirName . 'models/forms/settings3.php'; -// echo '
'.print_r($form, true).'
'; - include $this->pluginDirName . 'views/front/form_1.php'; - } - } else { - wp_die('An Error!:('); - } - break; case 3: + case 4: if ($this->formSubmitted) { - include $this->pluginDirName . 'models/forms/settings3.php'; - $this->form_process($form, 3); + $form = $this->load_form_settings($formPart); + $this->form_process($form, $formPart); $this->appId = $appId = filter_var($_REQUEST['appId'], FILTER_VALIDATE_INT); if ($this->errorCount > 0) { include $this->pluginDirName . 'views/front/form_1.php'; } else { - $this->store_form_data($form, 3); + $this->store_form_data($form, $formPart); // next form part - $formPart = 3; - include $this->pluginDirName . 'models/forms/settings4.php'; -// echo '
'.print_r($form, true).'
'; + ++$formPart; + $form = $this->load_form_settings($formPart); include $this->pluginDirName . 'views/front/form_1.php'; } } else { @@ -238,17 +228,8 @@ class glm_employment_front public function form_process(&$form, $part) { $this->clean_post(); - switch($part) { - case 1: - include $this->pluginDirName . 'models/forms/settings.php'; - break; - case 2: - include $this->pluginDirName . 'models/forms/settings2.php'; - break; - case 3: - include $this->pluginDirName . 'models/forms/settings3.php'; - break; - } + $form = $this->load_form_settings($form, $part); + foreach ($form as $rowKey => $row) { if ($row['type'] != 'header') { foreach ($row as $fieldKey => $field) { -- 2.17.1