Jump to content

Recommended Posts

Okay I have two droplists "system" and "genre" and a submit button.

 

1. How can I create code that would execute when the button is pressed?

2. How can I take the values of "system" and "genre" and put them into a string variable that have the pages current URL, but appends the values to the end and then reloads the page with those variables passed in the URL?

 

Example:

Current URL "http://www.something.com/page.php"

System value "1"

Genre value "1"

 

Reload the page with "http://www.something.com/page.php?system=1&genre=1"

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/
Share on other sites

Okay I have two droplists "system" and "genre" and a submit button.

 

1. How can I create code that would execute when the button is pressed?

2. How can I take the values of "system" and "genre" and put them into a string variable that have the pages current URL, but appends the values to the end and then reloads the page with those variables passed in the URL?

 

Example:

Current URL "http://www.something.com/page.php"

System value "1"

Genre value "1"

 

Reload the page with "http://www.something.com/page.php?system=1&genre=1"

 

Thanks!

 

Hmm...Almost sounds like homework.

 

Have you tried something like:

 

<?php
if(isset($_GET['submit']))
{
   if(isset($_GET['system']) && isset($_GET['genre']))
   {
      /* load the content specific for that system and genre */
   }
   else
   {
      /* error? */
   }
}

/*if the info HASN'T been submitted yet */
?>

<html>
<head>
   <title>Blah</title>
</head>

<body>
   <form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
      <select name="system">
         <!-- all of the 'system' options go here -->
      </select>

      <select name="genre">
         <!-- all of the 'genre' options go here -->
      </select>

      <input type="submit" name="submit" value="Submit" />
   </form>
</body>

</html>

how you ever tried

 

<body>
<form id="form1" name="form1" method="link" action="somepage.php?">
  <table>
    <tr>
      <td><select name="system">
      	<option value="system_option_1">system_option_1</option>
        <option value="system_option_2">system_option_2</option>
      </select>      </td>
      <td><select name="genre">
      	<option value="genre_option_1">genre_option_1</option>
        <option value="genre_option_2">genre_option_2</option>
      </select>      </td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" value="Submit" /></td>
    </tr>
  </table>
</form>
</body>

Perfect ideas. I went with the first one and here's what I got.

 

<form method="get" name="vgames" action="<?php $_SERVER['PHP_SELF'] ?>">
          <table align="left" cellpadding="0" cellspacing="0" border="0">
            <tr>
              <td bgcolor="#993366">
                <?php $vein->list_systems(1,$_GET['systems']); echo " "; $vein->list_genres(2,$_GET['genres']); ?> <input name='search' type='submit' class='button' tabindex='3' value='Search now'/><br>
                <?php $vein->list_numalpha_games($_GET['systems']); ?>
              </td>
            </tr>
          </table>
          </form>

 

Now here's the URL it produces "http://www.something.com/site/vgames.php?systems=6&genres=4&search=Search+now".  How can I get it to ignore search, which is the button?

But by using the mentioned method it's automatically taking all values from all form items within the form tags and applying them to the action which is reloading the page.  how can I get it to ignore search?

 

you can simply remove name attribute from form element.

i.e.  <input type="text" value="Some_Value">

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.