Help passing url appended value as hidden form input via php

Discussion in 'PHP' started by Aviators, May 30, 2008.

  1. #1
    Hi,

    I'm a complete noob- was hoping that someone might be able to point me in the right direction.

    I'm simply trying to have subdomain.mysite.com/California?click=1234 pass the value of "1234" as a hidden value under the name 'click' when the form is submitted.

    This value will be passed in the url and not generated from a form on another page (PPC landing page to track individual media sources).

    The only php expression I have at the top of the page is: <?php $state = (!empty($_GET['state'])) ? str_replace('WashingtonDC', 'Washington D.C.', $_GET['state']) : ''; ?> (to simply allow me to echo the state which is in each url onto the page.

    I have the following code:

    <input type="hidden" name="click" value="<?php echo $_GET["click"]; ?>">

    However when I load the page and view the source I don't see anything for the value except "".

    If I hardcode something for the value it passes to the second page and ties into my system their beautifully.

    Can I not use that PHP expression within a value="" tag?

    The full form code is:

    <form action="http://subdomain.mysite.com/searchresults.php" id="quoteform" name="quoteform" method="get">

    <div class="getQuote">








    <h1>Get a Free Quote Now</h1>


    <span class="enterZip">Simply Enter Your Zip Code</span>


    <!-- Appear the <span> if zip code is invalid -->


    <img src="/images/arrows.gif" alt="" align="top" border="0">

    <!-- <input type="text" class="zipCode" name="zip" id="search_string" value="Zip Code" size="7" maxlength="5" -->
    <input class="zipCode" name="zipcode" id="search_string" size="7" tabindex="1" maxlength ="5" type="text">



    <input type="hidden" name="click" value="<?php echo $_GET["click"]; ?>">


    <input src="/images//button_go_landing.gif" value="submit" id="image1" name="image1" align="top" type="image">

    <p class="Quote">Save up to <span class="savings">$400</span> or more!<br />

    </p>
    </div>

    <!-- Graphic for quote area -->
    <img src="/images/backgrond_image_for_form.jpg" alt="Save up to $400" border="0">
    <!-- End "Get A Quote" area -->


    </form>

    I presume this is a simple fix, I'll paypal a beer ($5) to the first person who can help me get this working.

    Thanks
     
    Aviators, May 30, 2008 IP
  2. swordbeta

    swordbeta Banned

    Messages:
    225
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That is really strange, it should work perfectly...look, it's working for me: click
     
    swordbeta, May 30, 2008 IP
  3. Aviators

    Aviators Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    AHA!

    Got it- I wasn't going to index.php- simply to mysite.com. As soon as I stuck index.php on there it worked. Thanks. Fire me your paypal via pm for the effort and I'll fire a drink your way.

    Cheers!
    Lars

    edit: while doing that works I now can't have mysite/california (or mysite/nebraska) and have this function. Any other thoughts?
     
    Aviators, May 30, 2008 IP
  4. Dagon

    Dagon Active Member

    Messages:
    122
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Could you clarify please?
     
    Dagon, May 30, 2008 IP
  5. Aviators

    Aviators Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Dagon-

    I think I've narrowed the issue down to the following:

    In my htaccess I have this:

    DirectoryIndex index.php
    RewriteEngine On
    RewriteRule ^([^/.]+)/?$ index.php?state=$1 [L]

    Then at the top of my index page I have <?php $state = (!empty($_GET['state'])) ? str_replace('WashingtonDC', 'Washington D.C.', $_GET['state']) : ''; ?>

    If I navigate to mysite.com/California (or any other "directory" <that doesn't really exist>), it parses this value in my page where I've called <?=$state?>.

    If I go to mysite.com/California?click=1234 my hidden field as detailed above is empty.

    IF I go to mysite.com?click=1234 the "1234" value shows up.

    I believe that my mod rewrite expression and possibly the first line of php need to be altered to allow me to go to mysite.com/California?click=1234 and have a) "California" still show up where <?=$state?> is, AND have my hidden field grab the "click" value of 1234

    (again that bit of code is <input type="hidden" name="click" value="<?php echo $_GET["click"]; ?>">)

    Thanks,
     
    Aviators, May 30, 2008 IP
  6. Dagon

    Dagon Active Member

    Messages:
    122
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Try this rewrite rule instead :
    RewriteRule ^([^/.]+)/?$ index.php?state=$1&%{QUERY_STRING} [L]

    PS: where do you live that beer costs $5? You'll be poor before getting drunk :)
     
    Dagon, May 31, 2008 IP
  7. Aviators

    Aviators Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    THANK YOU! That works brilliantly. :)

    I'm in Southern California (Orange County) PM me your paypal account.
     
    Aviators, May 31, 2008 IP