I’m trying to put together a custom add-on controller to handle a variety of form submissions that I intend users to have access to. I do not want to use the built-in form builder, as I want to handle the form code myself.
I managed to put together a small test framework by reviewing the docs & looking at profile.update procedures. I am able to get a basic form up, but I keep running into problems with the submission thru POST.
The controller, customforms.php fires, as well as a php file I include from inside customforms.php. But, the form content of the test.tpl template never appears when I submit the form back to the same page. The source code of the served page always has a blank line inside the
The docs say all controllers need to return array(CONTROLLER_STATUS_OK,…); for all POST methods, but it doesn’t seem to make a difference in my scenario. My POST code will simply validate the form submission, and provide some visual feedback thru CSS on corrections the user needs to make, or execute a server side script to process the form.
…/cscart/index.php?dispatch=customforms.test
CustomForms.php
```php if ( !defined('AREA') ) { die('Access denied'); }
//Require login - should return user to requested URL after sign in
if (empty($auth['user_id'])) {
return array(CONTROLLER_STATUS_REDIRECT, "auth.login_form?return_url=".urlencode(Registry::get('config.current_url')));
}
$skin_path = DIR_SKINS .Registry::get('config.skin_name');
$view->assign('skin_path', $skin_path);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//get php include for this particular form/mode name
$customform_phpfile = $skin_path ."/customer/views/customforms/" .$mode .".php";
include $customform_phpfile;
return array(CONTROLLER_STATUS_OK);
}
else {
if ($mode == 'view') {
fn_add_breadcrumb(fn_get_lang_var('customforms'));
$customforms_settings = fn_get_settings('customforms');
$view->assign('customforms_settings', $customforms_settings);
$view->assign('customforms', $customforms);
}
else {
//get php include for this particular form/mode name
$customform_phpfile = $skin_path ."/customer/views/customforms/" .$mode .".php";
include $customform_phpfile;
return array(CONTROLLER_STATUS_OK);
}
}
?> ```test.php - included from customforms.php above
```php /* This file gets called form customforms.php thru $mode - it is processed before the main form content */
include_once $skin_path ."/customer/views/customforms/formvalidator.php";
$page_title = "Installation Certificate CF-6R-MECH-21-HERS";
$form_title = "Installation Certificate CF-6R-MECH-21-HERS";
$show_form = true;
$show_thank_you = false;
$error_hash = array();
$show_error = false;
if($_SERVER['REQUEST_METHOD'] == "POST")
{
//Stuff $_POST values into $vars
$post_vars = getRealPOST();
$validator = new FormValidator();
//since the validation errors echo is commented out a few lines below, the error description parameter here really doesn't matter
$validator->addValidation("site_address","req","Site Address Required");
$validator->addValidation("enforcement_agency","req","Enforcement Agency Required");
$validator->addValidation("permit_number","req","Permit Number Required");
$validator->addValidation("duct_leakage_test_option","req","You must select a Duct Leakage Test option 1-4");
$validator->addValidation("fan_airflow_method","req","You must select a Fan Airflow method");
$validator->addValidation("company_name","req","Required Field");
$validator->addValidation("person_responsible","req","Required Field");
$validator->addValidation("cslb_license","req","Required Field");
$validator->addValidation("date_signed","req","Required Field");
$validator->addValidation("position_with_company","req","Required Field");
$validator->addValidation("third_party_quality_control","req","Required Field");
if($validator->ValidateForm())
{
$show_form = false;
$show_thank_you = true;
$pdf_email_sent = include_once('form_email_pdf.php'); //true or false if completed
if ($pdf_email_sent) {echo "EMAIL SENT";} else { echo "NOT SENT";}
}
else
{
$error_hash = $validator->GetErrors();
$show_error = true;
}
}
else {
}
$view->assign('page_title', $page_title);
$view->assign('form_title', $form_title);
$view->assign('show_form', $show_form);
$view->assign('show_thank_you', $show_thank_you);
$view->assign('error_hash', $error_hash);
$view->assign('show_error', $show_error);
?> ```test.tpl
```php {if $show_error}
an error occurred!!
{* Display validation errors *}
{foreach from=$error_hash item=error_desc}
{$error_hash.error_desc}
{/foreach}
{else}
{$form_title}
{$form_title}
Duct Leakage Test - Existing Duct System
Site Address
{/if} ```Anyone have an ideas where I am going wrong?