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. :)

Link to comment
Share on other sites

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" );
   }

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.