Jump to content

Creating a form with multiple graphical buttons.


mobiius

Recommended Posts

Hello, I'm trying to create a form with multiple graphical buttons from a php DB. (The DB works fine by the way :) )

The below code works, but creates a standard button. (It posts $MyCars['CarID'] correctly and showmods.php displays as intended. I know that the below code is formatted for a graphical button with the type changed to submit rather than image, this is just an example of the code working as expected.)

   print( "      <form enctype='multipart/form-data' action='showmods.php' method='post'>\n" );
   $GetCars = mysql_query( "SELECT * FROM Car" );
   while ( $MyCars = mysql_fetch_array( $GetCars, MYSQL_ASSOC ) ) //Iterate through all Cars..
   {
      print( "         <input type='submit' src='".$MyCars['CarHeaderImage']."' name='SelectCar' value='".$MyCars['CarID']."'><br>\n" );
   }
   print( "      </form>\n" );

 

What I want to do, is change the standard button for an image, (which is populated from a DB), which when clicked, posts a variable to showmods.php. The below code does not function as expected:

   print( "      <form enctype='multipart/form-data' action='showmods.php' method='post'>\n" );
   $GetCars = mysql_query( "SELECT * FROM Car" );
   while ( $MyCars = mysql_fetch_array( $GetCars, MYSQL_ASSOC ) ) //Iterate through all Cars..
   {
      print( "         <input type='image' src='".$MyCars['CarHeaderImage']."' name='SelectCar' value='".$MyCars['CarID']."'><br>\n" );
   }
   print( "      </form>\n" );

The images work correctly, when clicked they open the showmods.php file correctly, but do not pass the intended variable.

 

The only $_POST data I get is SelectCar_X and SelectCar_Y, and not the actual data which should be held in the value field. (Which is what I want)

 

Can anyone think of a way to get the graphical button to actually post the contents of it's 'value' field and not just the X/Y coords of the mouse click? Google searching has not provided any working answers. :(

 

Thanks in advance. :)

lol, thanks for all the help, but I solved it myself by removing the form completely, and passing the required variable through the URL as in the example.

 

   $GetCars = mysql_query( "SELECT * FROM Car" );
   while ( $MyCars = mysql_fetch_array( $GetCars, MYSQL_ASSOC ) ) //Iterate through all Cars..
   {
      print( "         <a href='showmods.php?SelectCar=".$MyCars['CarID']."'><img src='".$MyCars['CarHeaderImage']."' border=0></a><br>\n" );
   }

I know. I posted here because the code I posted was for an html form. The serverside bit was irrelevant as it was how I was using the submit button in the form. Replacing the form with images within links and using a url parameter worked.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.