Zen Cart Logo
Forums / Customization from the Admin / Add custom form submission data access on Admin backend

Add custom form submission data access on Admin backend

Views: 2,594

Results 1 to 10 of 10
10 Sep 2015, 2:50 PM
#1
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Add custom form submission data access on Admin backend

Hi everyone,

I created application form for my client who now wants to have a feature of having any submissions saved in backend in table format where they can access any submission to edit/write notes/delete/export into csv.

Please let me know if this is possible. :cool:

Regards,

Fahad

10 Sep 2015, 5:31 PM
#2
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Re: Add custom form submission data access on Admin backend

Please let me know if anyone wants to see form code.

15 Sep 2015, 2:24 PM
#3
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Re: Add custom form submission data access on Admin backend

Any help?

15 Sep 2015, 3:17 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Add custom form submission data access on Admin backend

If understood correctly, the following is the case (please correct where necessary):

  1. On the store front, a form is presented to a customer.
  2. The customer enters data, and the form is submitted.
  3. The submission of the form stores information somewhere in the database and possibly performs other operations such as email or otherwise.
  4. To date, the form submission information is a one-way process such that the customer can not edit the form data, nor can the admin (other than performing SQL queries).
  5. Guessing that as a result of 4 above, there is no "notes" field in the table.
  6. To wrap the above up, now it is desired to be able to access the information stored in the database and perform actions on it such as edit and delete where in the edit process it would be possible to add notes to the record. Then it is desired to also be able to export the data for further review/manipulation.

This brings the following questions:
a. How are notes to be handled? Is there an expectation of knowing "when" a note was applied? Is there supposed to be only one note "block" per such form submission or is it like when reviewing an order's history that it is possible to apply additional notes at a later time(s) with specific action to be taken at the point of saving? (ie. notify the customer by email, log the action in the database but don't notify, or log in the database and keep hidden from the customer.)
b. Is the data only to be exported and not imported again?
c. Is there already some form of an admin panel generated to which these additional features are to be added? (ie. something that already displays the results of the form but does not yet edit it?)
d. More than likely would need to specifically provide the above requested results having the original form code (not just the code between <form> and </form> that is displayed to the customer) would make it easier in addition to the answers to the above.

23 Sep 2015, 6:51 PM
#5
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Re: Add custom form submission data access on Admin backend

mc12345678:

If understood correctly, the following is the case (please correct where necessary):

  1. On the store front, a form is presented to a customer.
  2. The customer enters data, and the form is submitted.
  3. The submission of the form stores information somewhere in the database and possibly performs other operations such as email or otherwise.
  4. To date, the form submission information is a one-way process such that the customer can not edit the form data, nor can the admin (other than performing SQL queries).
  5. Guessing that as a result of 4 above, there is no "notes" field in the table.
  6. To wrap the above up, now it is desired to be able to access the information stored in the database and perform actions on it such as edit and delete where in the edit process it would be possible to add notes to the record. Then it is desired to also be able to export the data for further review/manipulation.

This brings the following questions:
a. How are notes to be handled? Is there an expectation of knowing "when" a note was applied? Is there supposed to be only one note "block" per such form submission or is it like when reviewing an order's history that it is possible to apply additional notes at a later time(s) with specific action to be taken at the point of saving? (ie. notify the customer by email, log the action in the database but don't notify, or log in the database and keep hidden from the customer.)
b. Is the data only to be exported and not imported again?
c. Is there already some form of an admin panel generated to which these additional features are to be added? (ie. something that already displays the results of the form but does not yet edit it?)
d. More than likely would need to specifically provide the above requested results having the original form code (not just the code between <form> and </form> that is displayed to the customer) would make it easier in addition to the answers to the above.

Hi Mc12345678,

  1. Yes, form is presented in the store front
  2. Yes, customer enters data and the form is submitted
  3. The submission of the form is no stored in database but it is directly emailed to administrator
  4. Yes, forms cannot be edited
  5. Yes, there is no note field in the table

Desired solution:
I would like to store data in backend where only one comment/note field is provided where office staff can write comments. The data can only be exported from there. I don't want office personnel to import form submission. Maybe, they can have option to export certain dated submissions?
I can't find any feature that does this. I can provide form codes next.

23 Sep 2015, 6:59 PM
#6
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Re: Add custom form submission data access on Admin backend

../public_html/includes/modules/pages/request_demo/header_php.php

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright © 2003 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php|
// | |
// | Portions Copyright © 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is|
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt.|
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | license AT zen-cart DOT com so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: header_php.php,v 1.0 2015/05/13 00:00:00 Avenview Exp $
//
require(DIR_WS_MODULES . 'require_languages.php');

$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {

$rad_fullname = zen_db_prepare_input($_POST['rad_fullname']);
$rad_company = zen_db_prepare_input($_POST['rad_company']);
$rad_email = zen_db_prepare_input($_POST['rad_email']);
$rad_phone = zen_db_prepare_input($_POST['rad_phone']);
$rad_address1 = zen_db_prepare_input($_POST['rad_address1']);
$rad_address2 = zen_db_prepare_input($_POST['rad_address2']);
$rad_city = zen_db_prepare_input($_POST['rad_city']);
$rad_postal = zen_db_prepare_input($_POST['rad_postal']);
$rad_state = zen_db_prepare_input($_POST['rad_state']);
$rad_country = zen_db_prepare_input($_POST['rad_country']);
$rad_product = zen_db_prepare_input($_POST['rad_product']);
$commments = zen_db_prepare_input($_POST['comments']);


/* Added CAPTCHA Verification here */
  if (ACCOUNT_VALIDATION == 'true' && REQUEST_DEMO_VALIDATION == 'true') {
  $antirobotreg = zen_db_prepare_input($_POST['antirobotreg']);
  $sql = "SELECT * FROM " . TABLE_ANTI_ROBOT_REGISTRATION . " WHERE session_id = '" . zen_session_id() . "' LIMIT 1";
   if( !$result = $db->Execute($sql) ) {
    $error = true;
    $entry_antirobotreg_error = true;
    $text_antirobotreg_error = ERROR_VALIDATION_1;
    $messageStack->add('request_demo_validation', ERROR_VALIDATION_1);
    } else {
    $entry_antirobotreg_error = false;
    $antirobotrow = $db->Execute($sql);
        if (( strtolower($_POST['antirobotreg']) != $antirobotrow->fields['reg_key'] ) or ($antirobotrow->fields['reg_key'] =='')) {
        $error = true;
        $entry_antirobotreg_error = true;
        $text_antirobotreg_error = ERROR_VALIDATION_2;
        $messageStack->add('request_demo_validation', ERROR_VALIDATION_2);
        } else {
                $sql = "DELETE FROM " . TABLE_ANTI_ROBOT_REGISTRATION . " WHERE session_id = '" . zen_session_id() . "'";
                if( !$result = $db->Execute($sql) )
                {
                                $error = true;
                                $entry_antirobotreg_error = true;
                                $text_antirobotreg_error = ERROR_VALIDATION_3;
                               $messageStack->add('request_demo_validation', ERROR_VALIDATION_3);
                                } else {
                                $sql = "OPTIMIZE TABLE " . TABLE_ANTI_ROBOT_REGISTRATION . "";
                                        if( !$result = $db->Execute($sql) )
                                                {
                                                $error = true;
                                                $entry_antirobotreg_error = true;
                                                $text_antirobotreg_error = ERROR_VALIDATION_4;
                                                $messageStack->add('request_demo_validation', ERROR_VALIDATION_4);
                                                } else {
                                                $entry_antirobotreg_error = false;
                                 }
                                }
                    }
  }

    if (strlen($antirobotreg) <> ENTRY_VALIDATION_LENGTH) {
        $error = true;
        $entry_antirobotreg_error = true;
        } else {
        $entry_antirobotreg_error = false;
    }
}

/* End CAPTCHA Verification */
if (!zen_validate_email($rad_email)) {
$error = true;
}
if (!zen_not_null($rad_fullname)) {
$error = true;
}
if (!zen_not_null($rad_company)) {
$error = false;
}
if (!zen_not_null($rad_phone)) {
$error = true;
}
if (!zen_not_null($rad_address1)) {
$error = false;
}
if (!zen_not_null($rad_address2)) 
$error = false;
}
if (!isset($_POST['termsandconds']) || ($_POST['termsandconds'] != '1')) {
$error = true;
$messageStack->add_session('request_demo', 'You must accept our terms and conditions before demo request can be processed.', 'error');
}

if ($error == false) {

// grab some customer info if logged in
if($_SESSION['customer_id']) {
$check_customer = $db->Execute("select customers_id, customers_firstname, customers_lastname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'");
$customer_email= $check_customer->fields['customers_email_address'];
$customer_name= $check_customer->fields['customers_firstname'] . ' ' . $check_customer->fields['customers_lastname'];
} else {
$customer_email='Not logged in';
$customer_name='Not logged in';
}

//assemble the email contents:
      $email_text = 'Request A Demo: ' . "\n" .
        '------------------------------------------------------' . "\n" .
        'Fullname:' . "\t" . $rad_fullname . "\n" .
        'Company:' . "\t" . $rad_company . "\n" .
        'Email:' . "\t" . $rad_email . "\n" .
        'Phone:' . "\t" . $rad_phone . "\n" .
        'Address:' . "\t" . $rad_address1 . "\n" .
        'Address (optional):' . "\t" . $rad_address2 . "\n" .
        'City:' . "\t" . $rad_city . "\n" .
        'Postal:' . "\t" . $rad_postal . "\n" .
        'State/Province:' . "\t" . $rad_state . "\n" .
        'Country:' . "\t" . $rad_country . "\n" .
        'Product:' . "\t" . $rad_product . "\n" .
        'Commments:' . "\t" . $commments . "\n" ;
        OFFICE_USE . "\t" . "\n" .
        OFFICE_LOGIN_NAME . "\t" . $customer_name . "\n" .
        OFFICE_LOGIN_EMAIL . "\t" . $customer_email . "\n" .
        OFFICE_IP_ADDRESS . "\t" . $_SERVER['REMOTE_ADDR'] . "\n" .
        OFFICE_HOST_ADDRESS . "\t" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n" .
        OFFICE_DATE_TIME . "\t" . date("D M j Y G:i:s T") . "\n" .
        '------------------------------------------------------' . "\n\n" .
      $email_text = zen_output_string_protected($email_text);
      $email_html = nl2br("\n" . $email_text);

//send the email
      zen_mail(STORE_NAME, SEND_TO_ADDRESS, EMAIL_SUBJECT, $email_text, $rad_fullname , $rad_email, array('EMAIL_MESSAGE_HTML' => $email_html), 'request_demo');

zen_redirect(zen_href_link(FILENAME_REQUEST_DEMO, 'action=success'));
} //endif $error=false

// endif action

// default email and name if customer is logged in
if($_SESSION['customer_id']) {
$check_customer = $db->Execute("select customers_id, customers_firstname, customers_lastname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_id = '" . $_SESSION['customer_id'] . "'");
$email= $check_customer->fields['customers_email_address'];
$firstname= $check_customer->fields['customers_firstname'];
$lastname= $check_customer->fields['customers_lastname'];
}
?>
23 Sep 2015, 7:01 PM
#7
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Re: Add custom form submission data access on Admin backend

../public_html/includes/templates/template_default/templates/tpl_request_demo_default.php

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce                   |
// +----------------------------------------------------------------------+
// | Copyright © 2003 The zen-cart developers             |
// |                                   |
// | http://www.zen-cart.com/index.php                  |
// |                                   |
// | Portions Copyright © 2003 osCommerce               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license,   |
// | that is bundled with this package in the file LICENSE, and is    |
// | available through the world-wide-web at the following url:     |
// | http://www.zen-cart.com/license/2_0.txt.              |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to   |
// | license AT zen-cart DOT com so we can mail you a copy immediately.     |
// +----------------------------------------------------------------------+
// $Id: tpl_request_demo_default.php,v 1.0 2015/05/13 00:00:00 Avenview Exp $
//
?>

<STYLE>
BODY
{scrollbar-face-color: #528607; scrollbar-shadow-color: #3B6201; 
scrollbar-highlight-color: #639E0C; scrollbar-3dlight-color: #7BB625; 
scrollbar-darkshadow-color: #2C4901; scrollbar-track-color: #3F6A01; 
scrollbar-arrow-color: #D8FA2E}
</STYLE>
<?php echo zen_draw_form('request_demo', zen_href_link(FILENAME_REQUEST_DEMO, 'action=send')); ?>
<div><h1><?php echo HEADING_TITLE; ?></h1></div> 
<table width="100%" border="0" cellspacing="2" cellpadding="2" >
<?php
 if ($messageStack->size('request_demo') > 0) {
?>
<?php
 }

 if (isset($_GET['action']) && ($_GET['action'] == 'success')) {
?>
 <tr>
  <td class="plainBox" colspan="2"><?php echo TEXT_SUCCESS; ?></td>
 </tr>
 <tr>
  <td class="main" colspan="2"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT) . '</a>'; ?></td>
 </tr>
<?php
 } else {
?>
<tr>
  <td class="plainBoxHeading" colspan="2" valign="top" style="border-top:0px; border-bottom:0px; border-left:3px solid #ED1D26; background:#e1e1e1; color:#555;">Demo Request:</td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Product:<font color="#FF0000">*</font></td>
  <td class="main" valign="top"><select name="rad_product" style="width: 150px;">
<option value="">Please Select One</option>
<option value="Video Walls">Video Walls</option>
<option value="Multi Viewers">Multi Viewers</option>
<option value="Video Matrix Switches">Video Matrix Switches</option>
</select></td>
</tr>
<tr>
  <td class="plainBoxHeading" colspan="2" valign="top" style="border-top:0px; border-bottom:0px; border-left:3px solid #ED1D26; background:#e1e1e1; color:#555;">Customer Information:</td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Full Name:<font color="#FF0000">*</font></td>
  <td class="main" valign="top"><input type="text" name="rad_fullname"  style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Company:</td>
  <td class="main" valign="top"><input type="text" name="rad_company" style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Email:<font color="#FF0000">*</font></td>
  <td class="main" valign="top"><?php echo zen_draw_input_field('rad_email', ($error ? $_POST['rad_email'] : $email), ' size="10"'); ?></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Phone:<font color="#FF0000">*</font></td>
  <td class="main" valign="top"><input type="text" name="rad_phone" style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Address:</td>
  <td class="main" valign="top"><input type="text" name="rad_address1" style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Address (optional):</td>
  <td class="main" valign="top"><input type="text" name="rad_address2" style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">City:</td>
  <td class="main" valign="top"><input type="text" name="rad_city" style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Postal Code/Zip Code:</td>
  <td class="main" valign="top"><input type="text" name="rad_postal" style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">State/Province:</td>
  <td class="main" valign="top"><input type="text" name="rad_state" style="width: 150px;"></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Country:</td>
  <td class="main" valign="top"><select name="rad_country" style="width: 150px;">
	<option value="United States" title="United States">United States</option>
	<option value="Afghanistan" title="Afghanistan">Afghanistan</option>
	<option value="Åland Islands" title="Åland Islands">Åland Islands</option>
	<option value="Albania" title="Albania">Albania</option>
</select></td>
</tr>
<tr>
  <td class="plainBoxHeading" align="right" valign="top" width="100">Comments (optional):</td>
  <td class="main" valign="top"><?php echo zen_draw_textarea_field('comments', '45', '10', ''); ?></td>
</tr>
<tr>
  <td class="main" colspan="2" align="right" valign="top">I have read and agree to the <a target="popup" onclick="window.open('index.php?main_page=conditions','name','width=600,height=400')">user agreement</a>:<font color="#FF0000">*</font>
   <input type="checkbox" name="termsandconds" value="1"></td>
</tr>
 <tr>
  <td class="main" colspan="2"><?php echo $messageStack->output('request_demo'); ?></td>
 </tr>
<!--START CAPTCHA INPUT HERE -->

<?php
if (ACCOUNT_VALIDATION == 'true' && REQUEST_DEMO_VALIDATION == 'true') {
?>

<?php
if (strstr($_SERVER['REQUEST_URI'],'request_demo') && REQUEST_DEMO_VALIDATION == 'true' || strstr($_SERVER['REQUEST_URI'],'login') && LOGIN_VALIDATION == 'true') { 
?>

<?php
  if ($is_read_only == false || (strstr($_SERVER['REQUEST_URI'],'contact_us')) || (strstr($_SERVER['REQUEST_URI'],'login'))) {
    $sql = "DELETE FROM " . TABLE_ANTI_ROBOT_REGISTRATION . " WHERE timestamp < '" . (time() - 3600) . "' OR session_id = '" . zen_session_id() . "'";
    if( !$result = $db->Execute($sql) ) { die('Could not delete validation key'); }
    $reg_key = generate_captcha_code();
    $sql = "INSERT INTO ". TABLE_ANTI_ROBOT_REGISTRATION . " VALUES ('" . zen_session_id() . "', '" . $reg_key . "', '" . time() . "')";
    if( !$result = $db->Execute($sql) ) { die('Could not check registration information'); }
?>
<tr>
  <td class="main" colspan="3" align="right" valign="top">
<legend><?php echo CATEGORY_ANTIROBOTREG; ?></legend>
<?php if ($messageStack->size('request_demo') > 0) echo $messageStack->output('request_demo_validation'); ?>
<?php
$validation_images = '';
for($i = 0; $i < ENTRY_VALIDATION_LENGTH; $i++)
    {
    $parse_image = 'validation/validation_' . $reg_key{$i} . '.gif';
    $parse_image_alt = $reg_key{$i};
    $validation_images .= zen_image(DIR_WS_IMAGES . $parse_image, $parse_image_alt);
    }
    echo '<div class="centered">';
    echo $validation_images . '<br />';
    echo '</div>';
?>


<?php echo zen_draw_input_field('antirobotreg','', 'id="antirobotreg"') . (zen_not_null(ENTRY_ANTIROBOTREG) ? '<span class="alert">' . ENTRY_ANTIROBOTREG_TEXT . '</span>': ''); ?>
<br class="clearBoth" />

<?php
    }
?>

<?php
    }
?>

<?php
    }
?>
<!-- END CAPTCHA INPUT -->
</td></tr>
<tr>
  <td><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT) . '</a>'; ?></td>
  <td><?php echo zen_image_submit('button_send.gif', REQUEST_DEMO); ?></td>
 </tr>
<?php
 }
?>
</table></form>
23 Sep 2015, 7:02 PM
#8
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Re: Add custom form submission data access on Admin backend

../public_html/includes/languages/english/request_demo.php

<?php
//
// +----------------------------------------------------------------------+
// |zen-cart Open Source E-commerce |
// +----------------------------------------------------------------------+
// | Copyright © 2003 The zen-cart developers |
// | |
// | http://www.zen-cart.com/index.php |
// | |
// | Portions Copyright © 2003 osCommerce |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the GPL license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.zen-cart.com/license/2_0.txt. |
// | If you did not receive a copy of the zen-cart license and are unable |
// | to obtain it through the world-wide-web, please send a note to |
// | license AT zen-cart DOT com so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// $Id: request_demo.php,v 1.0 2015/05/13 00:00:00 Avenview Exp $
//

define('HEADING_TITLE', 'Request A Demo');
define('NAVBAR_TITLE', 'Request A Demo');
define('TEXT_SUCCESS', 'Your request has been successfully sent.');
define('EMAIL_SUBJECT', 'Demo Request from ' . STORE_NAME);

define('ENTRY_NAME', 'Full Name:');
define('ENTRY_EMAIL', 'E-Mail Address:');
define('ENTRY_ENQUIRY', 'Message:');

define('SEND_TO_ADDRESS','email...');
define('REQUEST_DEMO','SUBMIT');
?>

../public_html/includes/extra_datafiles/request_demo.php

<?php
// define the filenames used in the project
define('FILENAME_REQUEST_DEMO', 'request_demo');
?>
9 Feb 2016, 4:18 PM
#9
fahadali avatar

fahadali

New Zenner

Join Date:
May 2015
Location:
Mississauga, Ontario, Canada
Posts:
14
Plugin Contributions:
0

Re: Add custom form submission data access on Admin backend

Hi everyone,

Its been a while. Does somebody knows how to do this?

Regards,

Fahad

12 Feb 2016, 1:59 AM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Add custom form submission data access on Admin backend

You might find some inspiration in the code that stores customer reviews, as it's also collecting data from the visitor and storing it in a table, which can then be viewed on the Admin side ... with the ability for the Admin user to edit and approve those reviews before they're shown on the front-end.