Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Custom form doesn't work

    I'm having some difficulty getting a custom form to work. I have set up the capability to designate a product a gift for someone else. Currently, I have instructed the customer to change the shipping address to the name and address of the gift recipient. Some have complained that the approach is confusing (maybe my wording is unclear) and the customer can't order products that are not gifts in the same order. So I am setting up a form that comes up when the "gift" is added to the cart. I have made a file for use in extra_cart_actions that detects the gift and brings up a form. Since I want name, address, email address, telephone etc. the code for the form is a modified version of create_account.php and the related template files.

    The file in extra_cart_actions is correctly loading the equivalent of create_account.php. On the first pass through that file, some variables are set. Then the template should be drawn based on the equivalent of tpl_create_account_default.php. But the processing flow never gets to that file. The weird thing about this is that it worked properly all the way through, including displaying the form, processing the entered data and completing adding the gift to cart exactly once. After going into some unrelated code to send the gathered data in an email, and coming back and purchasing the gift again, the form never comes up. Instead, the product is added to the cart as usual and no data on the recipient is generated.

    After debugging, I found that the equivalent of tpl_create_ account_default.php was never entered. So how does code execution go from create_account.php to tpl_create_account_default on the first pass when the form should be drawn? I'm stuck.

    Zen cart version 155f, php version 7.1.x

    TIA for any help.

    Dave

  2. #2
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Custom form doesn't work

    Unfortunately it seems that more than pure discussion would be helpful.

    By "going into" create_account.php, are you referring to the module file? Have you redirected to your "page" that provides the equivalent functionality of create account? What session value(s) are being set that should be cleared once the purchase is made? What verification is present that the data expected to support moving forwards has been completed?

    Basically what data is still present as part of the recheckout process that wasn't there before and how does it affect your program flow?

    These things might be easier to identify with actual code. If the code is provided, please be sure to paste it between [CODE][/CODE] tags that are created by pressing the # button in the messagebox toolbar while writing your response.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,681
    Plugin Contributions
    123

    Default Re: Custom form doesn't work

    Why don't you just use my gift wrap mod?
    https://www.zen-cart.com/downloads.php?do=file&id=267
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  4. #4
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Custom form doesn't work

    Thank you MC...
    I'll try and answer each question and then provide the code.

    1. By "going into" create_account.php, are you referring to the module file? - Yes, includes/modules/MY_TEMPLATE/create_account.php.

    2. Have you redirected to your "page" that provides the equivalent functionality of create account? - Yes, includes/modules/MY_TEMPLATE/membership_gift_data.php. Instead of redirect, I'm using include in the extra cart action file so the remainder of the "add new product to cart" process is completed.

    3. What session value(s) are being set that should be cleared once the purchase is made? - Session values are set for gift_recipient_first_name, gift_recipient_last_name, gift_recipient_street_address, gift_recipient_suburb, gift_recipient_city, gift_recipient_state, gift_recipient_postcode, gift_recipient_country_zone_id, gift_recipient_country_id, gift_recipient_zone_id, gift_recipient_telephone, gift_member_number, and gift_recipient_email_address.

    4. What verification is present that the data expected to support moving forwards has been completed? - successfully meeting all the data requirements in membership_gift_data.php after the form is sumitted.

    5. Basically what data is still present as part of the recheckout process that wasn't there before and how does it affect your program flow? - the session values mentioned above. The session gift_recipient_first_name is used to bypass going through the process again should additional "add product to cart" for the membership gift product occur.

    Now for the code...
    Note that the code is a work in progress.

    1. extra_cart_action file:
    Code:
    <?php
    global $messageStack;
    
    if ($_GET['action'] == 'add_product') {
    	if (isset($_POST['products_id']) && $_POST['cart_quantity'] > 0 && $_POST['products_id'] == MEMBERSHIP_PID) {
        	if (isset($_POST['id'])) {
    			foreach($_POST['id'] as $option => $value) {
            		if ($option == GIFT_OPTION_NUMBER && $value == GIFT_VALUE_NUMBER_YES) {
            			if (!isset($_SESSION['gift_recipient_first_name'])) {
           				// display recipients additional data form
    						require(DIR_WS_MODULES . zen_get_module_directory(FILENAME_GIFT_DATA));
                		}
            		}
        		}
        	}
        }      
    }
    2. membership_gift_data.php placed in includes/modules/MY_TEMPLATE/
    Code:
    <?php
    /**
     * membership_gift_data.php
     *	Modified version of includes/modules/febt_store_template/create_account.php
     *  	to capture membership gift recipients data
     *
     * @package modules
     * @copyright Copyright 2003-2016 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: Author: zcwilt Fri Apr 15  Modified in v1.5.5 $
     */
    global $db, $messageStack;
    if (!defined('IS_ADMIN_FLAG')) {
      die('Illegal Access');
    }
    /**
     * Set some defaults
     */
      $process = false;
      $zone_name = '';
      $entry_state_has_zones = '';
      $error_state_input = false;
      $state = '';
      $zone_id = 0;
      $error = false;
      $member_number_OK = FALSE;
    
    /**
     * Process form contents
     */
    if (isset($_POST['action']) && ($_POST['action'] == 'process')) {
      $process = true;
      $gift_antiSpam = isset($_POST['should_be_empty']) ? zen_db_prepare_input($_POST['should_be_empty']) : '';
    
      $gift_firstname = zen_db_prepare_input(zen_sanitize_string($_POST['firstname']));
      $gift_lastname = zen_db_prepare_input(zen_sanitize_string($_POST['lastname']));
      $gift_email_address = zen_db_prepare_input($_POST['email_address']);
      $gift_street_address = zen_db_prepare_input($_POST['street_address']);
      if (ACCOUNT_SUBURB == 'true') $gift_suburb = zen_db_prepare_input($_POST['suburb']);
      $gift_postcode = zen_db_prepare_input($_POST['postcode']);
      $gift_city = zen_db_prepare_input($_POST['city']);
      if (ACCOUNT_STATE == 'true') {
        $gift_state = zen_db_prepare_input($_POST['state']);
        if (isset($_POST['zone_id'])) {
          $gift_zone_id = zen_db_prepare_input($_POST['zone_id']);
        } else {
          $gift_zone_id = false;
        }
      }
      $gift_country = zen_db_prepare_input($_POST['zone_country_id']);
      $gift_telephone = zen_db_prepare_input($_POST['telephone']);
      
      if (strlen($gift_firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
        $error = true;
        $gift_error['firstname'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_FIRST_NAME_ERROR);
      }
    
      if (strlen($gift_lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
        $error = true;
        $gift_error['lastname'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_LAST_NAME_ERROR);
      }
    
      if (strlen($gift_email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
        $error = true;
        $gift_error['email address'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_EMAIL_ADDRESS_ERROR);
      } elseif (zen_validate_email($gift_email_address) == false) {
        $error = true;
        $gift_error['email address validation'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
      }
    
      if (strlen($gift_street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
        $error = true;
        $gift_error['street address'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_STREET_ADDRESS_ERROR);
      }
    
      if (strlen($gift_city) < ENTRY_CITY_MIN_LENGTH) {
        $error = true;
        $gift_error['city'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_CITY_ERROR);
      }
    
      if (ACCOUNT_STATE == 'true') {
        $check_query = "SELECT count(*) AS total
                        FROM " . TABLE_ZONES . "
                        WHERE zone_country_id = :zoneCountryID";
        $check_query = $db->bindVars($check_query, ':zoneCountryID', $gift_country, 'integer');
        $check = $db->Execute($check_query);
        $entry_state_has_zones = ($check->fields['total'] > 0);
        if ($entry_state_has_zones == true) {
          $zone_query = "SELECT distinct zone_id, zone_name, zone_code
                         FROM " . TABLE_ZONES . "
                         WHERE zone_country_id = :zoneCountryID
                         AND " .
                         ((trim($gift_state) != '' && $gift_zone_id == 0) ? "(upper(zone_name) like ':zoneState%' OR upper(zone_code) like '%:zoneState%') OR " : "") .
                        "zone_id = :zoneID
                         ORDER BY zone_code ASC, zone_name";
    
          $zone_query = $db->bindVars($zone_query, ':zoneCountryID', $gift_country, 'integer');
          $zone_query = $db->bindVars($zone_query, ':zoneState', strtoupper($gift_state), 'noquotestring');
          $zone_query = $db->bindVars($zone_query, ':zoneID', $gift_zone_id, 'integer');
          $zone = $db->Execute($zone_query);
    
          //look for an exact match on zone ISO code
          $found_exact_iso_match = ($zone->RecordCount() == 1);
          if ($zone->RecordCount() > 1) {
            while (!$zone->EOF && !$found_exact_iso_match) {
              if (strtoupper($zone->fields['zone_code']) == strtoupper($gift_state) ) {
                $found_exact_iso_match = true;
                continue;
              }
              $zone->MoveNext();
            }
          }
    
          if ($found_exact_iso_match) {
            $gift_zone_id = $zone->fields['zone_id'];
            $gift_zone_name = $zone->fields['zone_name'];
          } else {
            $error = true;
            $gift_error['state'] = 1;
            $error_state_input = true;
            $messageStack->add('membership_gift_data', ENTRY_STATE_ERROR_SELECT);
          }
        } else {
          if (strlen($gift_state) < ENTRY_STATE_MIN_LENGTH) {
            $error = true;
            $gift_error['state length'] = 1;
            $error_state_input = true;
            $messageStack->add('membership_gift_data', ENTRY_STATE_ERROR);
          }
        }
      }
    
      if (strlen($gift_postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
        $error = true;
        $gift_error['postcode'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_POST_CODE_ERROR);
      }
    
      if ( (is_numeric($gift_country) == false) || ($gift_country < 1) ) {
        $error = true;
        $gift_error['country'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_COUNTRY_ERROR);
      }
    
      if (strlen($gift_telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
        $error = true;
        $gift_error['telephone'] = 1;
        $messageStack->add('membership_gift_data', ENTRY_TELEPHONE_NUMBER_ERROR);
      }
    
    /*
    	Add FEBT number and validate against member list
    */
      $gift_member_number = zen_db_prepare_input($_POST['member_number']);
      $_SESSION['gift_is_member'] = FALSE;
      $_SESSION['gift_member_number'] = '';
      if ($gift_member_number <> "") {
    	$gift_febt_number = find_member_number(0, $gift_lastname, $gift_firstname, $gift_street_address, $gift_postcode, $gift_city, $gift_state, $gift_country, $gift_zone_id);
        if (substr($gift_febt_number, 0, 3) == "ERR") { 
          // name and address fail to match any member in febt database
          $error = TRUE;
          $gift_error['member no match'] = 1;
          $messageStack->add('membership_gift_data', ERROR_FEBT_MEMBER_VALIDATION_NAME_OR_ADDRESS_ERROR, 'error');
        } else {
    	  // number returned
    	  if ($gift_febt_number !== $gift_member_number) {
    		// name and address match a member but the number is wrong
    		$error = TRUE;
    		$gift_error['wrong member number'] = 1;
    		$messageStack->add('membership_gift_data', ERROR_FEBT_MEMBER_VALIDATION_NUMBER_ERROR, 'error');
    	  } else {
    	    // customer number, name and address match, set data
    		$_SESSION['gift_is_member'] = TRUE;
    		$_SESSION['gift_member_number'] = $gift_member_number;
    	  } // end of number, name and address match
    	} // end of number returned from find_member_number
      } // end of $member_number <> ""
    /*
    	End of FEBT number validation
    */
    
      if ($error == true) {
        // hook notifier class
      } elseif ($gift_antiSpam != '') {
        $messageStack->add_session('header', (defined('ERROR_CREATE_ACCOUNT_SPAM_DETECTED') ? ERROR_CREATE_ACCOUNT_SPAM_DETECTED : 'Thank you, your account request has been submitted for review.'), 'success');
        zen_redirect(zen_href_link(FILENAME_SHOPPING_CART));
      } else {
    
        $_SESSION['gift_recipient_first_name'] = $gift_firstname;
        $_SESSION['gift_recipient_last_name'] = $gift_lastname;
        $_SESSION['gift_recipient_street_address'] = $gift_street_address;
        $_SESSION['gift_recipient_suburb'] = $gift_suburb;
        $_SESSION['gift_recipient_city'] = $gift_city;
        $_SESSION['gift_recipient_state'] = $gift_state;
        $_SESSION['gift_recipient_postcode'] = $gift_postcode;
        $_SESSION['gift_recipient_zone_country_id'] = $gift_zone_country_id;
        $_SESSION['gift_recipient_country_id'] = $gift_country;
        $_SESSION['gift_recipient_zone_id'] = $gift_zone_id;
        $_SESSION['gift_recipient_telephone'] = $gift_telephone;
        $_SESSION['gift_recipient_email_address'] = $gift_email_address;
        
    //     zen_redirect(zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL'));
    
      } //endif !error
    }
    
    /*
     * Set flags for template use:
     */
      $selected_country = (isset($_POST['zone_country_id']) && $_POST['zone_country_id'] != '') ? $country : SHOW_CREATE_ACCOUNT_DEFAULT_COUNTRY;
      $flag_show_pulldown_states = ((($process == true || $entry_state_has_zones == true) && $zone_name == '') || ACCOUNT_STATE_DRAW_INITIAL_DROPDOWN == 'true' || $error_state_input) ? true : false;
      $state = ($flag_show_pulldown_states) ? ($state == '' ? '&nbsp;' : $state) : $zone_name;
      $state_field_label = ($flag_show_pulldown_states) ? '' : ENTRY_STATE;
    3. tpl_membership_gift_data_default.php placed in includes/templates/MY_TEMPLATE/templates/
    Code:
    <?php
    /**
     * Page Template
     *
     * Loaded automatically by index.php?main_page=create_account.<br />
     * Displays form to enter membership gift data.
     *
     * @package templateSystem
     * @copyright Copyright 2003-2007 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_membership_gift_data_default.php febt file $
     */
    ?>
    <div class="centerColumn" id="createAcctDefault">
    
    <h3 id="createAcctDefaultHeading"><?php echo GIFT_FORM_TITLE; ?></h3>
    
    <?php echo zen_draw_form('membership_gift_data', zen_href_link(FILENAME_GIFT_DATA, '', 'SSL'), 'post', 'onsubmit="return check_form(membership_gift_data);"') . zen_draw_hidden_field('action', 'process'); ?>
    
    <fieldset>
    <legend><?php echo GIFT_FORM_LEGEND; ?></legend>
    
    <?php require($template->get_template_dir('tpl_modules_membership_gift_data_form.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_membership_gift_data_form.php'); ?>
    
    </fieldset>
    
    <div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_SUBMIT, BUTTON_SUBMIT_ALT); ?></div>
    </form>
    </div>
    4. tpl_modules_membership_gift_data_form.php placed in includes/templates/MY_TEMPLATE/templates/
    Code:
    <?php
    /**
     * Page Template
     *
     * Loaded automatically by index.php?main_page=create_account.<br />
     * Displays membership gift data form.
     *
     * @package templateSystem
     * @copyright Copyright 2003-2016 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: rbarbour zcadditions.com Fri Feb 26 00:03:33 2016 -0500 Modified in v1.5.5 $
     */
    ?>
    
    <fieldset>
    <legend><?php echo TABLE_HEADING_ADDRESS_DETAILS; ?></legend>
    
    <label class="inputLabel" for="firstname"><?php echo ENTRY_FIRST_NAME; ?></label>
    <?php echo zen_draw_input_field('firstname', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_firstname', '40') . ' id="firstname" placeholder="' . ENTRY_FIRST_NAME_TEXT . '"' . ((int)ENTRY_FIRST_NAME_MIN_LENGTH > 0 ? ' required' : '')); ?>
    <br class="clearBoth" />
    
    <label class="inputLabel" for="lastname"><?php echo ENTRY_LAST_NAME; ?></label>
    <?php echo zen_draw_input_field('lastname', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_lastname', '40') . ' id="lastname" placeholder="' . ENTRY_LAST_NAME_TEXT . '"'. ((int)ENTRY_LAST_NAME_MIN_LENGTH > 0 ? ' required' : '')); ?>
    <br class="clearBoth" />
    
    <label class="inputLabel" for="street-address"><?php echo ENTRY_STREET_ADDRESS; ?></label>
      <?php echo zen_draw_input_field('street_address', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_street_address', '40') . ' id="street-address" placeholder="' . ENTRY_STREET_ADDRESS_TEXT . '"'. ((int)ENTRY_STREET_ADDRESS_MIN_LENGTH > 0 ? ' required' : '')); ?>
    <br class="clearBoth" />
    
    <?php echo zen_draw_input_field('should_be_empty', '', ' size="40" id="CAAS" style="visibility:hidden; display:none;" autocomplete="off"'); ?>
    
    <?php
      if (ACCOUNT_SUBURB == 'true') {
    ?>
    <label class="inputLabel" for="suburb"><?php echo ENTRY_SUBURB; ?></label>
    <?php echo zen_draw_input_field('suburb', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_suburb', '40') . ' id="suburb" placeholder="' . ENTRY_SUBURB_TEXT . '"'); ?>
    <br class="clearBoth" />
    <?php
      }
    ?>
    
    <label class="inputLabel" for="city"><?php echo ENTRY_CITY; ?></label>
    <?php echo zen_draw_input_field('city', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_city', '40') . ' id="city" placeholder="' . ENTRY_CITY_TEXT . '"'. ((int)ENTRY_CITY_MIN_LENGTH > 0 ? ' required' : '')); ?>
    <br class="clearBoth" />
    
    <?php
      if (ACCOUNT_STATE == 'true') {
        if ($flag_show_pulldown_states == true) {
    ?>
    <label class="inputLabel" for="stateZone" id="zoneLabel"><?php echo ENTRY_STATE; ?></label>
    <?php
          echo zen_draw_pull_down_menu('zone_id', zen_prepare_country_zones_pull_down($selected_country), $zone_id, 'id="stateZone"');
          if (zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert">' . ENTRY_STATE_TEXT . '</span>';
        }
    ?>
    
    <?php if ($flag_show_pulldown_states == true) { ?>
    <br class="clearBoth" id="stBreak" />
    <?php } ?>
    
    <label class="inputLabel" for="state" id="stateLabel"><?php echo $state_field_label; ?></label>
    <?php
        echo zen_draw_input_field('state', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_state', '40') . ' id="state" placeholder="' . ENTRY_STATE_TEXT . '"');
        if ($flag_show_pulldown_states == false) {
          echo zen_draw_hidden_field('zone_id', $zone_name, ' ');
        }
    ?>
    <br class="clearBoth" />
    <?php
      }
    ?>
    
    <label class="inputLabel" for="postcode"><?php echo ENTRY_POST_CODE; ?></label>
    <?php echo zen_draw_input_field('postcode', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_postcode', '40') . ' id="postcode" placeholder="' . ENTRY_POST_CODE_TEXT . '"' . ((int)ENTRY_POSTCODE_MIN_LENGTH > 0 ? ' required' : '')
    ); ?>
    <br class="clearBoth" />
    
    <label class="inputLabel" for="country"><?php echo ENTRY_COUNTRY; ?></label>
    <?php echo zen_get_country_list('zone_country_id', $selected_country, 'id="country" ' . ($flag_show_pulldown_states == true ? 'onchange="update_zone(this.form);"' : '')) . (zen_not_null(ENTRY_COUNTRY_TEXT) ? '<span class="alert">' . ENTRY_COUNTRY_TEXT . '</span>': ''); ?>
    <br class="clearBoth" />
    </fieldset>
    
    <fieldset>
    <legend><?php echo TABLE_HEADING_PHONE_FAX_DETAILS; ?></legend>
    <label class="inputLabel" for="telephone"><?php echo ENTRY_TELEPHONE_NUMBER; ?></label>
    <?php echo zen_draw_input_field('telephone', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_telephone', '40') . ' id="telephone" placeholder="' . ENTRY_TELEPHONE_NUMBER_TEXT . '"' . ((int)ENTRY_TELEPHONE_MIN_LENGTH > 0 ? ' required' : ''), 'tel'); ?>
    
    <br class="clearBoth" />
    <label class="inputLabel" for="member_number"><?php echo ENTRY_MEMBER_NUMBER; ?></label>
    <?php echo zen_draw_input_field('member_number', $account->fields['customers_member_number'], 'id="member_number"') . (zen_not_null(ENTRY_MEMBER_NUMBER_TEXT) ?
    '<span class="alert">' . ENTRY_MEMBER_NUMBER_TEXT . '</span>': ''); ?>
    </fieldset>
    
    <fieldset>
    <legend><?php echo TABLE_HEADING_LOGIN_DETAILS; ?></legend>
    <label class="inputLabel" for="email-address"><?php echo ENTRY_EMAIL_ADDRESS; ?></label>
    <?php echo zen_draw_input_field('email_address', '', zen_set_field_length(TABLE_CUSTOMERS, 'customers_email_address', '40') . ' id="email-address" placeholder="' . ENTRY_EMAIL_ADDRESS_TEXT . '"' . ((int)ENTRY_EMAIL_ADDRESS_MIN_LENGTH > 0 ? ' required' : ''), 'email'); ?>
    <br class="clearBoth" />
    </fieldset>
    5. header_php.php placed in includes/modules/pages/membership_gift_data/
    Code:
    <?php
    /**
     * membership_gift_data header_php.php
     *
     * @package page
     * @copyright Copyright 2003-2006 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: header_php.php 4035 2006-07-28 05:49:06Z drbyte $
     * febt file
     */
    
    require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
    include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_GIFT_DATA));
    
    $breadcrumb->add(NAVBAR_TITLE);
    All the javascript files in includes/modules/pages/create_account/ folder were copied and placed in the includes/modules/pages/membership_gift_data folder.

    6. There's also a file containing definitions of the constants new to the above files. it's febt_membership_gift_data_definitions and placed in includes/languages/english/extra_definitions.
    Code:
    <?php
    //
    // +----------------------------------------------------------------------+
    // |zen-cart Open Source E-commerce                                       |
    // +----------------------------------------------------------------------+
    // | Copyright (c) 2004 The zen-cart developers                           |
    // |                                                                      |   
    // | http://www.zen-cart.com/index.php                                    |   
    // |                                                                      |   
    // | Portions Copyright (c) 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       |
    // | [email protected] so we can mail you a copy immediately.          |
    // +----------------------------------------------------------------------+
    // $Id: febt_membership_gift_data_definitions.php $
    //
    
    DEFINE('MEMBERSHIP_PID', '601');
    DEFINE('GIFT_OPTION_NUMBER', '26');
    DEFINE('GIFT_VALUE_NUMBER_YES', '88');
    DEFINE('FILENAME_GIFT_DATA', 'membership_gift_data');
    DEFINE('ERROR_GIFT_ERROR', 'Sorry, only one membership gift per order is allowed');
    DEFINE('GIFT_FORM_TITLE', 'Please fill out form and click Submit');
    DEFINE('GIFT_FORM_LEGEND', 'Membership gift recipients information');
    The program flow I want is:
    The customer checks a "gift" box on the product info page and clicks the add to cart button. For this product, if the session variable is not set, membership_gift_data.php is "included" through a require statement. The file included is membership_gift_data.php. The $_POST['action'] variable is not "process", so only a few variables are set. Then the form should be drawn using tpl_membership_gift_data_default followed by tpl_membership_gift_data_form.php. The customer fills out the form and clicks submit. Processing goes to membership_gift_data.php after passing through the form_check function and the header file. Now $_POST['action'] is set to "process", and further tests are made on the inputs. If any errors, a message is displayed and the form is drawn again. If no errors, processing returns to the extra_cart_action file and eventually the add product to cart process finishes.

    The sequence of files must be set with include statements but I don't know where they are. I guess I could use an include statement to the template file in the first pass-through path in membership_gift_data.php.

    Hope all this helps you MC.

    Dave

  5. #5
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Custom form doesn't work

    In the code above, I used an "include" in the extra_cart_actions file to go to the file that either brings up the form or processes the data from the form. That approach never displayed the form. Switching to a "redirect" in the extra_cart_actions file brings up the form correctly, allows me to enter data in the form, and processes the data. Now I want to return somewhere in the "add product to cart" path to complete entering the product, but where? Any suggestions?

  6. #6
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,474
    Plugin Contributions
    88

    Default Re: Custom form doesn't work

    The processing in the /extra_cart_actions files are transitive in nature, normally resulting in a redirect once the 'action' is completed. I don't know if that is causing your expected results to differ from those actually created.

  7. #7
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Custom form doesn't work

    Thank you Lat9 but it still doesn't work if I interpreted your comment correctly. As mentioned in post 5, the file in the extra_cart_actions folder redirects to the file that processes the form data. First time through this file, the form is drawn. After the form is filled out and the submit button clicked, the file is called a second time to process the form data. At the end of this path, I thought I needed a redirect to some place in the "add product to cart" path. If I delete this redirect as I interpreted from your post, the form is drawn again empty (no data in it). A little troubleshooting indicates that wherever processing goes, the session variables set during the second pass are destroyed completely. Any other suggestions?

  8. #8
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Custom form doesn't work

    A couple things about "data". When the redirect is performed, any $_POST data is lost. $_GET data will remain if included as part of building the redirect. $_SESSION data will remain provided the target location properly prepares for capturing data to be sent/doesn't lose the session. Considering that the redirect is to another ZC handled page, that aspect shouldn't be too much of a concern.

    So, using the redirect for this situation (being presented with an additional web-page) appears to be a good idea especially since the remainder of the shopping cart operation can't really complete without processing this additional information.

    Often the extra_cart_actions are used to do additional work on the provided data in preparation for the shopping cart itself to be displayed (or to prevent it's display if the conditions are not correct).

    In your case you are wanting to hold the customer from reaching the cart until they have completed other operations. At the same time you want to return to the action that was being performed if they have completed their action.

    So basically you want to process your extra_cart_actions code if they have added the product and haven't done the desired action. You also want to be able to leave the cart and come back to it without having to redo those actions possibly unless they have removed that product from the cart... or maybe you don't want them to have to redo that action until they have gone through checkout where a product check may be performed to confirm that the applicable product is present or not...

    Anyways, in order to resume with the add-to-cart operation, one way to do this is to capture all of the posted data before the redirect and place it in a session variable. As part of displaying the new page, take that session data and include it as hidden data to again be posted.

    Thing from here though is that you probably also want to do some data validation on the information that is/has been entered onto this page. Two ways/places for that, either in areas like header_php.php for the page by posting the page back to itself, or by posting the page back to the add-to-cart operation and having your extra_cart_actions file realize (by some flag) that it is now to validate and continue to process the data or if sent back to the same page then in processing again the posted data would need to be collected in support of redirecting to the add-to-cart where the extra_cart_actions file would need to again restore data for continued processing through the shopping cart...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: Custom form doesn't work

    Quote Originally Posted by Dave224 View Post
    Thank you Lat9 but it still doesn't work if I interpreted your comment correctly. As mentioned in post 5, the file in the extra_cart_actions folder redirects to the file that processes the form data. First time through this file, the form is drawn. After the form is filled out and the submit button clicked, the file is called a second time to process the form data. At the end of this path, I thought I needed a redirect to some place in the "add product to cart" path. If I delete this redirect as I interpreted from your post, the form is drawn again empty (no data in it). A little troubleshooting indicates that wherever processing goes, the session variables set during the second pass are destroyed completely. Any other suggestions?
    If you're losing your session data, then perhaps the form is not being drawn correctly/the security token not being posted?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  10. #10
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: Custom form doesn't work

    Many thanks to everyone who has helped me with this form problem. The form is basically working and the input data processed correctly. I'm now cleanup a few loose ends. When the form is first displayed, an input field is displayed just below the dropdown state menu. But in the create account form, from which I based my custom form on, the unlabeled input box is not displayed. The following code from tpl_modules_create_account.php addresses the area of the form in question.
    Code:
    <?php
      if (ACCOUNT_STATE == 'true') {
        if ($flag_show_pulldown_states == true) {
    ?>
    <label class="inputLabel" for="stateZone" id="zoneLabel"><?php echo ENTRY_STATE; ?></label>
    <?php
          echo zen_draw_pull_down_menu('zone_id', zen_prepare_country_zones_pull_down($selected_country), $zone_id, 'id="stateZone"');
          if (zen_not_null(ENTRY_STATE_TEXT)) echo '&nbsp;<span class="alert">' . ENTRY_STATE_TEXT . '</span>';
        }
    ?>
    
    <?php if ($flag_show_pulldown_states == true) { ?>
    <br class="clearBoth" id="stBreak" />
    <?php } ?>
    <label class="inputLabel" for="state" id="stateLabel"><?php echo $state_field_label; ?></label>
    <?php
        echo zen_draw_input_field('state', '', zen_set_field_length(TABLE_ADDRESS_BOOK, 'entry_state', '40') . ' id="state" placeholder="' . ENTRY_STATE_TEXT . '"');
        if ($flag_show_pulldown_states == false) {
          echo zen_draw_hidden_field('zone_id', $zone_name, ' ');
        }
    ?>
    <br class="clearBoth" />
    <?php
      }
    ?>
    I can see no way of not executing the code in red and displaying an input field. But when creating an account the input field is not shown and in my custom form code with the same code, the input field is shown. I've compared the code in both places, forced the variables entering the code to be identical, and the result is the same. Help!

    TIA,
    Dave

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v154 The Contact Us Form Doesn't appear
    By sapir39 in forum General Questions
    Replies: 2
    Last Post: 3 May 2015, 02:39 PM
  2. Replies: 3
    Last Post: 30 Jun 2011, 04:41 PM
  3. My form submit button doesn't work
    By timjbart in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 21 Aug 2008, 11:25 PM
  4. My contact us form doesn't work...
    By bubblegumgoods in forum General Questions
    Replies: 24
    Last Post: 14 May 2006, 01:58 AM
  5. The Contact Us form...doesn't!
    By paults in forum General Questions
    Replies: 7
    Last Post: 10 May 2006, 03:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR