Results 1 to 7 of 7
  1. #1
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Appending checkbox selections to URL through form
    Ok, I have a [post] form with several elements (most of them select menus and input boxes). I'm adding an area with multiple checkboxes from which you can select.

    What I'm trying to accomplish is getting all of the checkbox selections and add them individually to a URL (all of the elements are gathered through the "action" file and then appended to a URL and redirected).

    Such as:

    url.com/blah.php?[existing variables]&choice=1&choice=2&choice=3

    All of the checkboxes are uniquely named (name1, name2, name3...).

    Shawn Kerr (.com) | Disney World | SEC Football

  2. #2
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    So, is this not possible?

    Shawn Kerr (.com) | Disney World | SEC Football

  3. #3
    Affiliate Manager adambha's Avatar
    Join Date
    October 20th, 2006
    Posts
    301
    So, unless I'm reading this wrong, what you're trying to do is pretty easy.
    Code:
    <form name="search_something" action=/blah.php method="get">
    <input type=checkbox name="choice1">Choice 1<br>
    <input type=checkbox name="choice2">Choice 2<br>
    <input type=checkbox name="choice3">Choice 3<br>
    <input type=checkbox name="choice4">Choice 4<p>
    <input type=submit value="Search">
    </form>
    Then, whatever is selected will appear in the URL as variable=on

    For example, if you selected Choice 1 and Choice 3, the URL would appear as

    mydomain.com/blah.php?choice1=on&choice3=on

    If a checkbox is not checked, it will not appear at all in the URL.

    You can also throw in drop-downs (select, option value..) text boxes or whatever, and they will appear in the URL as well.

    Hope that helps.

  4. #4
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Thanks for poking your head in, Adam.

    Ok, maybe I didn't explain well enough. I'm creating a custom form to submit queries to Monster.com. The form is a POST form, and I'm already passing a few variables off.

    My processing ("action") file currently looks like:

    PHP Code:
    <?
    $q 
    $_POST["BodyContent:_ctl0:_tbKeywords"];
    $cnme $_POST["BodyContent:_ctl0:_tbCity"];
    $sid $_POST["BodyContent:_ctl5:_dropState"];
    header("Location: http://jobsearch.monster.com/Search.aspx?q=$q&cnme=$cnme&sid=$sid")
    ?>
    Since those are single choice options, it's the easy part.

    What I need to do is tack on the checkbox choices (all choices will be identified by fn= in the URL).

    So basically I need to keep what I have but end up with:

    Search.aspx?q=$q&cnme=$cnme&sid=$sid&fn=checkboxchoice&fn=checkboxchoice&fn=checkboxchoice

    Shawn Kerr (.com) | Disney World | SEC Football

  5. #5
    Affiliate Manager adambha's Avatar
    Join Date
    October 20th, 2006
    Posts
    301
    Okay, now we're on the same page.

    First, the actual form page:

    Code:
    <?php
    $cat = array(
       1    => 'Choice 1',
       2    => 'Choice 2',
       3    => 'Choice 3',
    );
    
    foreach($cat as $key => $value){
       $select .= "\t".'<input type=checkbox name="fn[]" value="'.$key.'">' . $value.'<br />'."\r\n";
    }
    
    $select .= '</select>';
    echo '<form name="search_something" action=/pathto/myactionfile.php method="post">';
    echo $select;
    echo '<input type=submit name="submit" value="Search"></form>';
    ?>
    Then, on your action processing page:

    Code:
    <?php
    $q = $_POST["BodyContent:_ctl0:_tbKeywords"];
    $cnme = $_POST["BodyContent:_ctl0:_tbCity"];
    $sid = $_POST["BodyContent:_ctl5:_dropState"]; 
    
    $fn = '';
    
    foreach($_POST['fn'] as $key=> $value) {
      $fn .= '&fn=' . $value;
    }
    
    header("Location: http://jobsearch.monster.com/Search.aspx?q=$q&cnme=$cnme&sid=$sid$fn");
    ?>
    Now, is this what you're looking for?

  6. #6
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Thanks. That looks like what I'm looking for. I knew there was a foreach probably involved but in my mind I just couldn't get it all together.

    I'll have to give it a try later, I don't even have all the checkboxes set up yet.

    Shawn Kerr (.com) | Disney World | SEC Football

  7. #7
    Affiliate Manager adambha's Avatar
    Join Date
    October 20th, 2006
    Posts
    301
    Good deal, I hope this does the trick.

    Let me know when everything is working...

  8. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. New Product Category: Musical Selections
    By Greg Bennett - AffiliateWindow in forum Affiliate Window - AW
    Replies: 0
    Last Post: April 6th, 2010, 05:34 PM
  2. Appending Variables to outgoing links in WordPress
    By Kevin in forum Blogging, Mobile and Social Media
    Replies: 3
    Last Post: November 6th, 2008, 09:28 AM
  3. Appending eBay links in my forum with affiliate code
    By Haltingpoint in forum eBay Partner Network
    Replies: 1
    Last Post: October 16th, 2008, 01:27 PM
  4. Appending links with member id's
    By Howard Gottlieb in forum ShareASale - SAS
    Replies: 1
    Last Post: January 19th, 2007, 07:13 PM
  5. Appending Links for tracking
    By Allen Nance in forum ShareASale - SAS
    Replies: 7
    Last Post: October 25th, 2005, 08:39 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
  •