Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1852
  • Last Modified:

How to make a checkbox required with PHP / Zen Cart

I'm trying to add a field to a pre-existing form in Zen Cart. The code is below. After the form submits, it goes to the payment page. On that page, there's code that checks if the field has been checked. If not, it will redirect back to the previous page and present the prompt to fill in the required checkbox.

The problem is that I can't determine the value of the checkbox in order to the conditional statement. I've tried everything... what can I do to grab that?

Note: everything works fine if I hard-code the conditional statement to true or false, so I just need a proper way of getting this conditional statement to work:

  if (!isset($_POST['conditions']) || ($_POST['conditions'] != '1')) {
    $messageStack->add_session('checkout_shipping', ERROR_CONDITIONS_NOT_ACCEPTED, 'error');
      zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
  }
<!-- Go to the bottom, find the comment, <!-- Experts Exchange - need help with this form: -->
 
<?php
/**
 * Page Template
 *
 * Loaded automatically by index.php?main_page=checkout_shipping.<br />
 * Displays allowed shipping modules for selection by customer.
 *
 * @package templateSystem
 * @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: tpl_checkout_shipping_default.php 5316 2006-12-21 02:25:58Z drbyte $
 */
?>
<div class="centerColumn" id="checkoutShipping">
 
<?php echo zen_draw_form('checkout_address', zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL')) . zen_draw_hidden_field('action', 'process'); ?>
 
<div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_CONTINUE_CHECKOUT, BUTTON_CONTINUE_ALT); ?></div>
<div class="buttonRow back"><?php echo '<strong>' . TITLE_CONTINUE_CHECKOUT_PROCEDURE . '</strong><br />' . TEXT_CONTINUE_CHECKOUT_PROCEDURE; ?></div>
<br class="clearBoth" />
 
<h1 id="checkoutShippingHeading"><?php echo HEADING_TITLE; ?></h1>
<?php if ($messageStack->size('checkout_shipping') > 0) echo $messageStack->output('checkout_shipping'); ?>
 
<?php
  if (zen_count_shipping_modules() > 0) {
?>
 
<h2 id="checkoutShippingHeadingMethod"><?php echo TABLE_HEADING_SHIPPING_METHOD; ?></h2>
 
<?php
    if (sizeof($quotes) > 1 && sizeof($quotes[0]) > 1) {
?>
 
<div id="checkoutShippingContentChoose" class="important"><?php echo TEXT_CHOOSE_SHIPPING_METHOD; ?></div>
 
<?php
    } elseif ($free_shipping == false) {
?>
<div id="checkoutShippingContentChoose"><?php echo TEXT_ENTER_SHIPPING_INFORMATION; ?></div>
 
<?php
    }
?>
<?php
    if ($free_shipping == true) {
?>
<div id="freeShip" class="important" ><?php echo FREE_SHIPPING_TITLE; ?>&nbsp;<?php echo $quotes[$i]['icon']; ?></div>
<div id="defaultSelected"><?php echo sprintf(FREE_SHIPPING_DESCRIPTION, $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) . zen_draw_hidden_field('shipping', 'free_free'); ?></div>
 
<?php
    } else {
      $radio_buttons = 0;
      for ($i=0, $n=sizeof($quotes); $i<$n; $i++) {
?>
 
<br class="clearBoth">
<fieldset>  
<legend><?php if (isset($quotes[$i]['icon']) && zen_not_null($quotes[$i]['icon'])) { echo $quotes[$i]['icon']; } ?>&nbsp;<?php echo $quotes[$i]['module']; ?></legend>
 
<?php
        if (isset($quotes[$i]['error'])) {
?>
      <div><?php echo $quotes[$i]['error']; ?></div>
<?php
        } else {
          for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) {
// set the radio button to be checked if it is the method chosen
            $checked = (($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']['id']) ? true : false);
 
            if ( ($checked == true) || ($n == 1 && $n2 == 1) ) {
            }
?>
<?php
            if ( ($n > 1) || ($n2 > 1) ) {
?>
<div class="important forward"><?php echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?></div>
<?php
            } else {
?>
<div class="important forward"><?php echo $currencies->format(zen_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax'])) . zen_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?></div>
<?php
            }
?>
 
<?php echo zen_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'id="ship-'.$quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id'].'"'); ?>
<label for="ship-<?php echo $quotes[$i]['id'] . '-' . $quotes[$i]['methods'][$j]['id']; ?>" class="checkboxLabel" ><?php echo $quotes[$i]['methods'][$j]['title']; ?></label>
<br class="clearBoth" />
<?php
            $radio_buttons++;
          }
        }
?>
 
<!-- Experts Exchange - need help with this form: -->
<?php
  if (DISPLAY_CONDITIONS_ON_CHECKOUT == 'true') {
?>
<h1 class="termsconditions">Important Shipping Check!</h1>
<div class="termsdescription">Shipping can be hot!!! Read  first: <a style="cursor:pointer" title="shipping information page in a popup" onclick="window.open('index.php?main_page=page&id=24','_blank','scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=40,top=20'); return true">these guidelines</a> first.
</div>
<?php echo  zen_draw_checkbox_field('conditions', '1', false, 'id="conditions"');?>
<label class="checkboxLabel" for="conditions">I understand my chocolate may melt if I choose Ground Shipping beyond 2 day transit time from NYC.</label>
<?php
  }
?>
 
</fieldset>
<?php
      }
    }
?>
 
 
<?php
  } else {
?>
<h2 id="checkoutShippingHeadingMethod"><?php echo TITLE_NO_SHIPPING_AVAILABLE; ?></h2>
<div id="checkoutShippingContentChoose" class="important"><?php echo TEXT_NO_SHIPPING_AVAILABLE; ?></div>
<?php
  }
?>
 
<br class="clearBoth" />
<h4 id="checkoutShippingHeadingAddress"><?php echo TITLE_SHIPPING_ADDRESS; ?> </h4>
 
<div id="checkoutShipto" class="floatingBox back">
<?php if ($displayAddressEdit) { ?>
<div class="buttonRow forward"><?php echo '<a href="' . $editShippingButtonLink . '">' . zen_image_button(BUTTON_IMAGE_CHANGE_ADDRESS, BUTTON_CHANGE_ADDRESS_ALT) . '</a>'; ?></div>
<?php } ?>
<address class=""><?php echo zen_address_label($_SESSION['customer_id'], $_SESSION['sendto'], true, ' ', '<br />'); ?></address>
</div>
<div class="floatingBox forward"><?php echo TEXT_CHOOSE_SHIPPING_DESTINATION; ?></div>
<br class="clearBoth" /><br />
 
</form>
</div>

Open in new window

0
JoeFletcher
Asked:
JoeFletcher
  • 2
1 Solution
 
v2MediaCommented:
Setting to true/false is all that's required. If the checkbox is not checked, the input name and value doesn't get sent with the headers. You only need to check whether it's in the post array at all.
0
 
v2MediaCommented:
No one answered? What's my post, chuck steak?
0
 
JoeFletcherAuthor Commented:
Sorry about that man! I literally posted this delete request without seeing your response. I never received an email from EE notifying me of a response, so when I got the "you have open questions" email, I simply went on to delete the question not seeing your post.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now