Jump to content

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.

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.