Zen Cart Logo
Forums / General Questions / Can't pass variables from the form to the handler script

Can't pass variables from the form to the handler script

Views: 658

Results 1 to 2 of 2
21 Sep 2011, 6:37 PM
#1
happylenz avatar

happylenz

New Zenner

Join Date:
Apr 2010
Posts:
3
Plugin Contributions:
0

Can't pass variables from the form to the handler script

Greetings!

I'm trying to create a form (questionnaire) with radio buttons that based on the costumers' answers would select products from the database and display them. I used modified Contact Us page as a base for my form and its handler. For some reason handler page doesn't process variables that I'm passing through. I used var_dump to trace an input in the handler script, and it seems like my form vars are going through, but I still can't process them. Here's a peace of code from my tpl_skin_test_default.php

<?php echo zen_draw_form('skin_test', zen_href_link(FILENAME_SKIN_TEST, 'action=send')); ?>

<?php if (CONTACT_US_STORE_NAME_ADDRESS== '1') { ?>
<address><?php echo nl2br(STORE_NAME_ADDRESS); ?></address>
<?php } ?>

<?php
  if (isset($_GET['action']) && ($_GET['action'] == 'success')) {
?>

<div class="mainContent success"><?php 

// this where I select final product from database after questions were processed 

$theProductId = $_GET['id'];
global $db;
$sql = "select products_model from " . TABLE_PRODUCTS . " where products_id = :productID:";
$sql = $db->bindVars($sql, ':productID:', $theProductId, 'integer');
$result = $db->Execute($sql);

if ($result->RecordCount() > 0) {
  echo 'Model number = ' . $result->fields['products_model'];
} else {
  echo 'Sorry, no record found for product number ' . $theProductId;
}

</div>

<div class="buttonRow"><?php echo zen_back_link() . zen_image_button(BUTTON_IMAGE_BACK, BUTTON_BACK_ALT) . '</a>'; ?></div>

<?php
  } else {
?>

<?php if (DEFINE_CONTACT_US_STATUS >= '1' and DEFINE_CONTACT_US_STATUS <= '2') { ?>
<div id="contactUsNoticeContent" class="content">
<?php
/**
 * require html_define for the contact_us page
 */
  require($define_page);
?>
</div>
<?php } ?>

<?php if ($messageStack->size('contact') > 0) echo $messageStack->output('contact'); ?>

<form name="test" method="get"> 
 <p>My age is <br />
    <label>
      <input type="radio" name="quest0" value="a1" id="quest0_0" />
      20s</label>
     
    <label>
      <input type="radio" name="quest0" value="a2" id="quest0_1" />
      30s</label>
      
    <label>
      <input type="radio" name="quest0" value="a3" id="quest0_2" />
      40s</label>
      <label>
         
      <input type="radio" name="quest0" value="a4" id="quest0_3" />
      50s</label>
      
    <label>
      <input type="radio" name="quest0" value="a5" id="quest0_4" />
      60+</label>
    <br />
  </p>
 <input name="submit" type="submit" value="Submit Test Results" />
  
</form>

This is header_php.php that handles the form ```php
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));

$error = false;
if (isset($_GET['action']) && ($_GET['action'] == 'send')) {
//Here I tried to see what vars were passed
// var_dump($_GET,$_POST);
// exit;

if (isset($_GET['quest0']) && ($_GET['quest0'] == 'a3'))
{

zen_redirect(zen_href_link(FILENAME_SKIN_TEST, 'action=success&id=1')); //THIS ONE supposed to work when I get 'a3' radio button checked

}

else

{ zen_redirect(zen_href_link(FILENAME_SKIN_TEST, 'action=success&id=2'));  // instead it always passes else variant}

} 

I think problem somewhere in this area ```php
if (isset($_GET['quest0']) && ($_GET['quest0'] == 'a3')) 
``` Script ignores it or something. 

Do you have any idea how can I fix it? I appreciate any help! Thank you.
21 Sep 2011, 8:04 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: Can't pass variables from the form to the handler script

You are adding <form> tags without first adding a </form> tag to close the form started by zen_draw_form(), thus you're creating an HTML error, and inadvertently submitting the wrong form.