Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting a <form> button to work properly

    Hello there,

    I am trying to get a dropdown form to work in my php template file. I have the form with the options working appropriatly.

    PHP Code:
                <!--Apparel DropDown-->
                <p>Select Style:</p>
                <form name="apparel">
                    <p align="center">
                        <select name="menu">
                        <option selected>Choose Style:</option>
                        <option value="<?php get_custom_field('buy_now1'TRUE); ?>">Standard</option>
                        <option value="<?php get_custom_field('buy_now2'TRUE); ?>">American Apparel | +$3</option>
                        <option value="<?php get_custom_field('buy_now3'TRUE); ?>">Standard Long-Sleeve | +$4</option>
                        <option value="<?php get_custom_field('buy_now4'TRUE); ?>">Women's T-Shirt</option>
                        <option value="<?php get_custom_field('buy_now5'TRUE); ?>">Kid's T-Shirt</option>
                        <option value="<?php get_custom_field('buy_now6'TRUE); ?>">Kid's Long-Sleeve | +$2</option>
                        </select>
                        <input type="button" onClick="location=document.apparel.menu.options[document.apparel.menu.selectedIndex].value;" value="GO">
                    </p>
                </form>
                <!--end Apparel Dropdown-->
    Now that code as I mentioned works. I add URLs into the custom fields into wordpres; buy_now1, buy_now2, etc. However that's not the issue. My template file has these lines of code following the form code above:

    PHP Code:
                    <input type="hidden" id="amount" name="amount" value="<?php echo $value[0];?>"/>     
                    <input type="hidden" name="buy_now" value="<?php get_custom_field('buy_now'TRUE); ?>" />         
                    <input type="hidden" name="currency_code" value="<?php echo $OPTION['wps_currency_code']; ?>" /> 
                  
                    <?php ?> 
                     
                    <input type="hidden" name="add" value="1" /> 
                     
                    <div class="shopform_btn buy_now"> 
                        <a href="<?php get_custom_field('buy_now'TRUE); ?><?php if($OPTION['wps_affili_newTab']) { ?> title="<?php _e('Opens is new tab','wpShop'); ?>" target="_blank"<?php ?>><?php _e('Buy Now','wpShop'); ?></a> 
                    </div>
    What I need to have happen is get the dropdown "GO" button to work as the new a href under div "shopform_btn buy_now". Basically depending on what is selected in the dropdown, the buy_now button changes to that URL. I have tried to replace <a href="<?php get_custom_field('buy_now', TRUE); ?>" with <a onClick="location=document.apparel.menu.options[document.apparel.menu.selectedIndex].value;" However that did not work, it just got me my 404 error page.

    Does that make sense? Please ask if I can help explain.

    I really appreciate any help on this matter.

    Lorne

  • #2
    Regular Coder
    Join Date
    Jun 2011
    Posts
    103
    Thanks
    0
    Thanked 13 Times in 13 Posts
    what actually happens when this script is run?
    Trying to use the javascript event "onclick" will not work here, Javascript and PHP do not interact since JS is client-side and PHP is server side.
    Also, maybe showing the function get_custom_class might help

  • #3
    New Coder
    Join Date
    Jun 2011
    Posts
    46
    Thanks
    1
    Thanked 2 Times in 2 Posts
    I'm not sure if there's an elegant solution to your problem or not. I think it would involve some code in javascript to interpret the selection before the submit button is hit. That is not my forte.

    However, if you're just looking for a solution and your programming in php, you could simply build the page to accept the basic form information and THEN forward the visitor to the correct page based on that input. It would be a 2 step process instead of 1, but it should work just fine.

    Also, you might be able to program a menu to do the same thing on selection. Is there a reason you want it to be part of a form as opposed to simply a menu?

  • #4
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply.

    Well honestly I'm new at PHP and learning slowly. I know html and css fairly well, but no pro by anymeans.

    So the reason I used a form was because I searched how to create a form with a button that reflects what the URL is dependant on what item in the dropdown form was selected. That form uses the onClick function and works successfully and I assumed it would work in my php to replace: <a href="<?php get_custom_field('buy_now', TRUE); ?>" but when the "buy_now" button is clicked with it doesnt' do anything when replacing
    PHP Code:
    <a href="<?php get_custom_field('buy_now'TRUE); ?>"
    with
    PHP Code:
    <a onClick="location=document.apparel.menu.options[document.apparel.menu.selectedIndex].value;" 
    But if there's a better way to use PHP with a menu, I'm open to trying it. Would you mind helping me set that up or possibly pointing me to a tutorial?

    I'd really appreciate this, I've been trying to get this going for some time now.

    Thanks so much,
    Lorne

  • #5
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just realized that this is in the HTML & CSS Forum. Perhaps I should repost it in PHP section?

  • #6
    New Coder
    Join Date
    Jun 2011
    Posts
    46
    Thanks
    1
    Thanked 2 Times in 2 Posts
    I'm not sure where you got the code, but I think you're trying to mix javascript (the onclick tag is a script NOT PHP) and php together. That's pretty tough.

    Also, can you show me a completed page where the basic menu works? It looks like there has to be more code in the header or another script that you're not posting here.

  • #7
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok so I put the dropdown back up on this webpage: http://activestatedesigns.com/flagsi...orado/coflag01

    But now the go button doesn't work. I was working on it yesterday and I swear I had it working at one point.

    But that URL has all the information on the page to help troubleshoot it. I will be able to play with it a bit more this afternoon hopefully to get the dropdown working as I had it yesterday. We'll see.

    The original tutorial I found: http://www.personal-computer-tutor.com/dropdownlist.htm

    My other thought was to maybe just make the "GO" button look like the Green Buy Now button from my template and disable the current buy now button. FYI, the green buy now button jumps to the standard shirt page. But when I change the dropdown it still jumps to that link. THat's what I'm trying to tie into this dropdown.

    Thanks,
    Lorne

  • #8
    New Coder
    Join Date
    Jun 2011
    Posts
    46
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Here is the most basic code possible for the menu you are trying to use (click view source)

    http://www.infolists.com/Untitled-3.html

    And yes, it does work.

    Now are you saying that you need php to generate what those links need to be for each item on the menu? Or can you enter the links directly for each page?

    It's not hard to use php to fill in those links IF you are already running php. It would help though if the names of the pages you are going to have some logical sequence to them that you can implement.

  • #9
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    kwdamp,

    I appreciate the sample code to use. However, when I implemented that into my code it will only work when two forms are in there (old one and the one you wrote)? Then I change the code of your sample one to the right URLs, and it works, but then I delete my old one and no worky

    Can you view this and see why it won't work? My site is here with your code: http://activestatedesigns.com/flagsi...orado/coflag01

    PHP Code:
                    <form name="apparel"> 
                        <p align="center"> 
                            <select name="menu"> 
                            <option selected>Choose One</option> 
                            <option value="<?php get_custom_field('buy_now1'TRUE); ?>">Standard</option> 
                            <option value="<?php get_custom_field('buy_now2'TRUE); ?>">American Apparel</option> 
                            <option value="<?php get_custom_field('buy_now3'TRUE); ?>">Standard Long-Sleeve</option> 
                            <option value="<?php get_custom_field('buy_now4'TRUE); ?>">Women's T-Shirt</option> 
                            <option value="<?php get_custom_field('buy_now5'TRUE); ?>">Kid's T-Shirt</option> 
                            <option value="<?php get_custom_field('buy_now6'TRUE); ?>">Kid's Long-Sleeve</option> 
                            </select> 
                            <input type="button" onClick="location=document.apparel.menu.options[document.apparel.menu.selectedIndex].value;" value="GO">
                        </p> 
                    </form>
    Then finally, a little css question, I can't seem to find out how they coded the current buy now button in my template file. DO you know how to make the new "GO" button look like the buynow button. I'll just remove the templates button and replace with this new form when I get it working.

    Thanks so much,
    Lorne

  • #10
    New to the CF scene
    Join Date
    Jun 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok odd thing is, I added a blank form infront of my other form and it now works. weird.

    Why is that?

    Now I'm trying to get the hover css to work and it isn't cooperating!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •