Jump to content

Possible? Multiple image/text submits on form..


monkeytooth

Recommended Posts

Is it possible to have multiple text/image form submits that have different values..

 

Like I know I can:

<input type="submit" value="thing1" name="submit">
<input type="submit" value="thing2" name="submit">
<input type="submit" value="thing3" name="submit">

 

and with a bit o php use the name element to get the value being used to then do what I want, but with an image/text style submit button the:

onclick="document.['mtlstsrv'].submit(); return false"

 

So is it possible?

 

 

Yes, you can have multiple submits.  However, it's best to give them different names.  You can probably work around that by doing something like:

<input type="submit" value="thing1" name="submit[]">
<input type="submit" value="thing2" name="submit[]">
<input type="submit" value="thing3" name="submit[]">

 

That may pass the submits to PHP/JavaScript as an array.  I haven't tested it myself, so I can't say with 100% certainty.  That said, for additional processing, you'll have to do some array manipulation in order to obtain the correct submit button.  That's why I think it's just easier to give them different names.  You can access them directly without having to jump through extra hoops.

I find it easier to give the submit buttons different names rather than passing them along to PHP as an array. If you passed them as an array you would need to validate each value, thereby giving each submit button a different appearance and having to write more code than necessary, whereas giving the submit buttons different names all of the submit buttons could appear the same (if you wanted them to). But regardless, I still find that giving the submit buttons different names easier.

 

I think form controls such as checkboxes should be passed as an array because then it saves code, rather than having to assign the POST data to individual variables you could just loop through the array or use array keys.

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.