Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010
    Posts
    3
    Plugin Contributions
    0

    Default 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 Code:
    <?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_BACKBUTTON_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>
        &nbsp;
        <label>
          <input type="radio" name="quest0" value="a2" id="quest0_1" />
          30s</label>
         &nbsp;
        <label>
          <input type="radio" name="quest0" value="a3" id="quest0_2" />
          40s</label>
          <label>
            &nbsp;
          <input type="radio" name="quest0" value="a4" id="quest0_3" />
          50s</label>
         &nbsp;
        <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 Code:
    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 Code:
    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.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default 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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. USPS - how do I pass variables to the module to add dimensions
    By petepdx in forum Addon Shipping Modules
    Replies: 0
    Last Post: 24 Mar 2013, 03:22 AM
  2. Replies: 3
    Last Post: 2 Dec 2010, 08:46 PM
  3. Is it better to use the script from my host, or download the files
    By Rusty105 in forum Installing on a Linux/Unix Server
    Replies: 10
    Last Post: 10 Apr 2010, 10:58 AM
  4. how can I pass the parameters from page1 to the cart?
    By joelitos2000 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 21 Mar 2010, 09:48 PM
  5. How can I remove the New Customer Profile Form from the Login Page?
    By jaxbakers in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 7 Oct 2006, 06:27 PM

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