Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Posts
    155
    Plugin Contributions
    1

    Default Dropdown Menu Selection Not Recognized

    Hi gang,

    Have a code question. I've taken the customer email dropdown menu and added it to an admin info box, along with a text input box for a monetary amount. The idea is to select the desired customer, enter an amount into the box, then submit the form and pass both values into a database table.

    When I submit this form, only the amount from the input box is received. I've tried it with JavaScript and without. Can't get the selected customer to be recognized no matter what I do. However, testing my code outside of Zen works perfectly - both values are recognized by the form.

    Any ideas on what I'm missing or doing wrong? Thanks for any suggestions! :)

  2. #2
    Join Date
    Apr 2009
    Posts
    155
    Plugin Contributions
    1

    Default Re: Dropdown Menu Selection Not Recognized

    Okay, I've made some progress. On one of many rewrite attempts, I screwed up the form generation code by not noticing an extra set of quotes, which broke the HTML of the form. The form displayed, although a little strangely. For S&Gs I decided to click a customer anyway. Sure enough, the customer's email address I had chosen showed in part of the URL in my address bar. Eureka! Well, sort of.

    After more analysis, my problem seems somehow related to the security token and the inherent form functions. Using zen_draw_form and zen_pull_down_menu create a perfect dropdown menu, except the security token is placed before the initial <select> of the dropdown menu when the code is parsed into HTML. That results in zero action when I submit.

    When the HTML was broken, the security token was behind the closing </select>, and I could see the sel=rel or whatever it was parameter in my address bar, followed by the customer's email address, which was followed by the security token. A weird mix of elation and disappointment, to say the least. ;)

    First attempt to fix: I've used two functions to break apart zen_draw_form. One has the beginning form tags and works like a dream. The drop down menu, which comes next and is the regular zen_pull_down_menu, also works like a dream. The post-form function does nada. How do I get the security token back in there? The easy lil' echo I've seen referenced everywhere doesn't do it for me.

    My next idea is to try and write one form function which will encompass all three parts of this particular form. I have no idea where the token is coming from though, because I'm in admin, on a separate page, which isn't a login page and doesn't require an additional password. It seems to be necessary, however, since the drop down selection goes nowhere without it.

    Any help here would be great. After you stop laughing, of course! ;)

  3. #3
    Join Date
    Apr 2009
    Posts
    155
    Plugin Contributions
    1

    Default Re: Dropdown Menu Selection Not Recognized

    I just love talking to myself. :)

    After much trial and error, PHP tutorials and head banging, I've arrived at one certain conclusion - I need glasses. LOL! No wonder the token echo didn't work for me. ;)

    The problem with my form seems to be something to do with its method. Which explains why I finally saw the customer's email address in my browser, even though the method had been set to post. Broken HTML with the method chopped reverted to get. Makes sense.

    What isn't making sense is that I still can't get the customer selection to be recognized. I've tried a million combinations of methods, code, functions, Javascript, no Javascript, all with the same result. When the method is post, I communicate with the server, but only the amount is recognized. When the method is get, I can see the customer email address has indeed been selected, but I get zero communication with the server. However, that illustrated another issue, where the customer email address has been encoded so the "@" sign has been replaced with its ASCII equivalent, "%40".

    Being I can't see what's being passed when the method is post, I have to assume the customer email address is being passed the same way as get. So I tried another hundred ways to change the ASCII back into the symbol. Doesn't seem anything is working because I get the same old thing, no customer selected. I've tried to make sure my forms (both <form> and <select>) each have different IDs and names (four different values to avoid confusion), the methods are correct (I got tired of switching back the retrieval code so now it's just set to request LOL!) and so is the form HTML. I had mentioned breaking apart the inherent Zen forms, which is what I'm using because it's easier for me to follow. I should also mention I get the same result using the native code. Clearly the token was the least of my problems. LOL!

    This is for a pretty cool mod I'm going to share, if that helps to know, so I hope someone can take a look and point out the dumb thing I must be doing. This code rendition includes onchange, which shouldn't be needed, just so you can see I'm not crazy. Green, yes, absolutely - crazy, no. Even if I do talk to myself. ;)

    PHP form:

    PHP Code:
    $customers get_audiences_list('email');

    $contents =   array('form' => zen_draw_pre_form('email''clist'zen_href_link(FILENAME_ACTION'&action=addnew')) . html_entity_decode(zen_draw_pull_down_menu('customers_email_address" id="cmail" onchange="document.email.customers_email_address.value=this.value'$customers) . zen_draw_post_form($zentoken) . '<input type="hidden" name="customers_email_address" value=""><input type="submit" value="" style="display: none">'));
    $contents[] = array('align' => 'left''text' => '<br>' TEXT_NEW_AMOUNT '<br>' zen_draw_input_field('amount'number_format($gInfo->amount2'.''') ));
    $contents[] = array('align' => 'center''text' => '<br>' zen_image_submit('button_insert.gif'IMAGE_INSERT) . '&nbsp;<a href="' zen_href_link(FILENAME_ACTION'page=' $_GET['page'] . '&gid=' $customers->customers_id) . '">' zen_image_button('button_cancel.gif'IMAGE_CANCEL) . '</a>'); 

    HTML form output:
    Code:
     <td width="25%" valign="top">
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr class="infoBoxHeading">
        <td class="infoBoxHeading"><b>Title</b></td>
      </tr>
      <tr class="infoBoxHeading">
        <td class="infoBoxHeading">Select a Customer from the Menu:</td>
      </tr>
    </table>
    <form id="clist" name="email" action="https://mystore.com/admin/action.php?&action=addnew" method="post"><select rel="dropdown" name="customers_email_address" id="cmail" onchange="document.email.customers_email_address.value=this.value">
    <option value="" selected="selected">Please Select</option>
    <option value="[email protected]">Last Name, First Name ([email protected])</option>
    <option value="[email protected]">Last Name, First Name ([email protected])</option>
    <option value="[email protected]">Last Name, First Name ([email protected])</option>
    </select>
    <input type="hidden" name="securityToken" value="1234567890987654321" /><input type="hidden" name="customers_email_address" value=""><input type="submit" value="" style="display: none">
    <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td align="left" class="infoBoxContent"><br>Input Amount:<br><input type="text" name="amount" value="0.00" /></td>
      </tr>
      <tr>
        <td align="center" class="infoBoxContent"><br><input type="image" src="includes/languages/english/images/buttons/button_insert.gif" border="0" alt="Insert" title=" Insert ">&nbsp;<a href="https://mystore.com/admin/action.php?page=1"><img src="includes/languages/english/images/buttons/button_cancel.gif" border="0" alt="Cancel" title=" Cancel "></a></td>
      </tr>
    </table>
    </form>

    PHP retrieval:
    PHP Code:

    $email_raw 
    $_REQUEST['customers_email_address'];
    $customerwho preg_replace('/%40/''@'$email_raw);  // preg_replace just happening to be the last of several filters and functions I've tried to get rid of the ASCII, including substr, iconv, html_entity_decode, urldecode, etc.
    $customer_select $db->Execute("select customers_id from " TABLE_CUSTOMERS " where customers_email_address = '" $customerwho "' and  customers_id = '" . (int)$customers_id "'");
    $customers_id zen_db_prepare_input($_REQUEST['customer_select']);
    $amount zen_db_prepare_input($_REQUEST['amount']); 

  4. #4
    Join Date
    Apr 2009
    Posts
    155
    Plugin Contributions
    1

    Default Re: Dropdown Menu Selection Not Recognized

    Just to close out this thread, clearly I figured it out. And have an appointment with an optometrist. LOL!

    In case it helps anyone else, my problem wasn't the PHP code per se, it was a combination of punctuation being out of whack and the HTML for the info box. It took a lot of trial and error to figure it out, but I've learned tons! And hope to learn tons more, too. :)

 

 

Similar Threads

  1. v155 Contact us dropdown menu not working properly
    By spminis in forum Basic Configuration
    Replies: 16
    Last Post: 20 Aug 2016, 10:34 PM
  2. v150 Css dropdown menu not function
    By soso838 in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 23 Jun 2012, 09:45 PM
  3. Dropdown Menu for Language Selection
    By MerchantPathway in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 11 Jan 2009, 03:06 AM
  4. CSS Dropdown menu not working for IE
    By kjkogi in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 9 Oct 2008, 12:07 PM
  5. dropdown menu not working in IE
    By dpecsok in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 2 Oct 2008, 04:39 PM

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