121 |
122 |
--------------------------------------------------------------------------------
/form.php:
--------------------------------------------------------------------------------
1 | false));
14 | }
15 |
16 | /**
17 | * If the user uninstalls the Form Builder or disables it, any public forms will stop working. This is called at the
18 | * top of the forms to output a simple "Offline" message. It's really just to prevent an ugly error.
19 | *
20 | * Note: this is DIFFERENT from the form offline message which is configured per form.
21 | */
22 | if (!Modules::checkModuleUsable("form_builder")) {
23 | echo <<< END
24 |
25 |
26 |
27 |
28 |
29 | This form is unavailable.
30 |
31 |
32 |
33 | END;
34 | exit;
35 | }
36 |
37 | $module = Modules::getModuleInstance("form_builder");
38 | $namespace = "form_builder_{$published_form_id}";
39 |
40 | // find out about the page: form / review / thanks. That determines what values we pass to processFormBuilderPage
41 | $config = Forms::getFormConfiguration($published_form_id);
42 |
43 | $form_id = $config["form_id"];
44 | $view_id = $config["view_id"];
45 |
46 | FormGenerator::deleteUnfinalizedSubmissions($form_id);
47 |
48 | // check that we have all the info we need (configured form, View etc)
49 | $error_code = FormGenerator::checkLiveFormConditions($config);
50 | if (!empty($error_code)) {
51 | $config["error_code"] = $error_code;
52 | FormGenerator::generateFormPage($config);
53 | exit;
54 | }
55 |
56 | if (isset($_GET["clear"])) {
57 | FormGenerator::clearFormBuilderFormSessions($namespace);
58 | header("location: $filename");
59 | }
60 |
61 | // check the form shouldn't be taken offline. This does some special logic to override the is_online == "no"
62 | // for cases where submissions have been started but the form is now offline
63 | $is_online = FormGenerator::checkFormOffline($config, $namespace);
64 | $config["is_online"] = ($is_online) ? "yes" : "no";
65 |
66 | // set up sessions and retrieve the field data already submitted
67 | list($new_session, $fields) = FormGenerator::initFormBuilderPage($form_id, $view_id, $namespace);
68 |
69 | // get the current submission ID
70 | $submission_id = isset($_SESSION[$namespace]["form_tools_submission_id"]) ? $_SESSION[$namespace]["form_tools_submission_id"] : "";
71 |
72 | // get an ordered list of the pages in this published form
73 | $page_params = array(
74 | "view_tabs" => ViewTabs::getViewTabs($view_id, true),
75 | "include_review_page" => ($config["include_review_page"] == "yes") ? true : false,
76 | "include_thanks_page_in_nav" => ($config["include_thanks_page_in_nav"] == "yes") ? true : false,
77 | "review_page_title" => $config["review_page_title"],
78 | "thankyou_page_title" => $config["thankyou_page_title"]
79 | );
80 |
81 | $all_pages = Forms::getAllFormPages($page_params);
82 | $page = CoreGeneral::loadField("page", "{$namespace}_form_page", 1, $namespace); // TODO...
83 |
84 | // one additional check: make sure the page they're attempting to look at is permitted. They have to pass
85 | // through each page in order to prevent people bypassing any field validation
86 | $page = FormGenerator::verifyPageNumber($page, $all_pages, $namespace);
87 |
88 | $next_page = $page + 1;
89 | $page_info = $all_pages[$page - 1];
90 | $page_type = $page_info["page_type"];
91 |
92 |
93 | $post_values = array();
94 | $params = array();
95 | if ($page_type == "thanks") {
96 | FormGenerator::clearFormBuilderFormSessions($namespace);
97 | } else {
98 | $params = array(
99 | "namespace" => $namespace,
100 | "published_form_id" => $published_form_id,
101 | "submission_id" => $submission_id,
102 | "config" => $config,
103 | "page" => $page,
104 | "page_type" => $page_type,
105 | "form_id" => $form_id,
106 | "view_id" => $view_id,
107 | "submit_button" => "form_tools_continue",
108 | "next_page" => "$filename?page=$next_page",
109 | "form_data" => $_POST,
110 | "file_data" => $_FILES,
111 | "no_sessions_url" => "$filename?page=1"
112 | );
113 |
114 | // we need to finalize the submission on the penultimate page. This can mean either the Review page or
115 | // the final form page if there's no Review page
116 | $num_pages = count($all_pages);
117 | if ($page_type == "review" || ($page >= $num_pages - 1)) {
118 | $params["finalize"] = true;
119 | }
120 |
121 | // just in case
122 | if ($page == $num_pages && isset($params["form_data"]["form_tools_continue"])) {
123 | $params["next_page"] = "";
124 | }
125 |
126 | list($g_success, $g_message) = FormGenerator::processFormBuilderPage($params);
127 |
128 | // if there were any validation errors, pass the error along to the page. It'll use it to know not to
129 | // redirecting and to show the error message
130 | if (!$g_success) {
131 | $config["validation_error"] = $g_message;
132 | }
133 | }
134 |
135 | // now generate and display the form
136 | FormGenerator::generateFormPage($config, $page, $submission_id);
137 |
--------------------------------------------------------------------------------
/smarty_plugins/function.page.php:
--------------------------------------------------------------------------------
1 | getTemplateVars();
21 | $form_id = $template_vars["form_id"];
22 | $view_id = $template_vars["view_id"];
23 | $current_page = $template_vars["current_page"];
24 |
25 | // this is only set for when the form is actually in use
26 | $submission_id = isset($template_vars["submission_id"]) ? $template_vars["submission_id"] : "";
27 |
28 | // a little odd, but we renamed "template_type" to "page_type" here, because it's a little clearer.
29 | // We already know we're dealing with a page
30 | $template_info = $template_vars["templates"]["page"];
31 | $page_type = $template_info["template_type"];
32 |
33 | // form and review pages are special: they get info about the view fields
34 | $get_view_field_info = false;
35 | $validation_js = "";
36 |
37 | if ($page_type == "form_page") {
38 | // workaround for Views that didn't arrange their fields into tabs
39 | $tabs = ViewTabs::getViewTabs($view_id, true);
40 | if (empty($tabs)) {
41 | $current_page = "";
42 | }
43 |
44 | $grouped_fields = ViewFields::getGroupedViewFields($view_id, $current_page, $form_id, $submission_id);
45 |
46 | // if the user just failed server-side validation, merge in whatever info was in the POST request with what's in $grouped_fields
47 | if (isset($template_vars["validation_error"]) && !empty($template_vars["validation_error"])) {
48 | $grouped_fields = FieldValidation::mergeFormSubmission($grouped_fields, $_POST);
49 | }
50 |
51 | // get whatever validation is needed for this page
52 | $validation_js = FieldValidation::generateSubmissionJsValidation($grouped_fields, array(
53 | "form_element_id" => "ts_form_element_id",
54 | "custom_error_handler" => "fb_validate"
55 | ));
56 |
57 | $get_view_field_info = true;
58 | } else {
59 | if ($page_type == "review_page") {
60 | $grouped_fields = ViewFields::getGroupedViewFields($view_id, "", $form_id, $submission_id);
61 | $get_view_field_info = true;
62 | }
63 | }
64 |
65 | if ($get_view_field_info) {
66 | // remove all system fields and fields marked as non-editable
67 | $updated_grouped_fields = array();
68 | foreach ($grouped_fields as $field_info) {
69 | $group = $field_info["group"];
70 | $fields = array();
71 | foreach ($field_info["fields"] as $field_info) {
72 | if ($field_info["is_system_field"] == "yes" || $field_info["is_editable"] == "no") {
73 | continue;
74 | }
75 |
76 | // a hack for a complicated scenario. The {display_custom_field} template doesn't set the settings
77 | // param like with the main program, so we re-use the {edit_custom_field} template and just tell it
78 | // that nothing is editable
79 | if ($page_type == "review_page") {
80 | $field_info["is_editable"] = "no";
81 | $field_info["submission_info"] = array();
82 | $field_info["submission_info"]["value"] = isset($field_info["submission_value"]) ? $field_info["submission_value"] : "";
83 | }
84 |
85 | $fields[] = $field_info;
86 | }
87 |
88 | if (!empty($fields)) {
89 | $updated_grouped_fields[] = array(
90 | "group" => $group,
91 | "fields" => $fields
92 | );
93 | }
94 | }
95 |
96 | $field_types = FieldTypes::get(true);
97 | $settings = Settings::get();
98 |
99 | $smarty->assign("grouped_fields", $updated_grouped_fields);
100 | $smarty->assign("field_types", $field_types);
101 | $smarty->assign("settings", $settings);
102 | }
103 |
104 | if (empty($template_info["content"])) {
105 | $template_info["content"] = " ";
106 | }
107 |
108 | $smarty->left_delimiter = '{{';
109 | $smarty->right_delimiter = '}}';
110 |
111 | $smarty->assign("eval_str", $template_info["content"]);
112 | $smarty->assign("page_name", $template_vars["nav_pages"][$current_page - 1]["page_name"]);
113 | $smarty->assign("page_type", $page_type);
114 |
115 | // used in the form action attribute. This'll cause nice "/" paths for index.php to get redirected to index.php on
116 | // the next redirect, which is a pity
117 | $smarty->assign("page_url", basename($_SERVER["SCRIPT_NAME"]));
118 |
119 | $page = $smarty->fetch("../../modules/form_builder/smarty_plugins/eval.tpl");
120 | if (!empty($validation_js)) {
121 | $error_handler_js = General::getFormValidationCustomErrorHandlerJs();
122 | $page = "" . $page;
123 | }
124 |
125 | return $page;
126 | }
127 |
--------------------------------------------------------------------------------
/templates/template_sets/tab_edit_placeholder.tpl:
--------------------------------------------------------------------------------
1 |
15 | {/if}
16 |
17 | {* used by the Form Builder to let it know whether or not the parent page is still on the Publish tab *}
18 |
19 |
20 | {if $form_info.form_type != "form_builder"}
21 |
22 |
32 |
33 | {else}
34 |
35 | {if $published_forms.results|@count == 0}
36 |
37 |