[development] Changing button #name?

Richard Morse remorse at partners.org
Wed Jun 23 16:02:32 UTC 2010


On Jun 23, 2010, at 11:37 AM, Adam Gregory wrote:

> Actually all buttons in a Drupal form have the name "op" so that you can
> easily determine which button was pressed in the submit function. i.e. if
> ($op = 'blah) or switch ($op).
> 
> If you are using the Drupal Ahah framework for this then your submit
> function should handle it. But since all your buttons are titled Remove,
> what you can do is use $form_state['clicked_button']['#id'] to determine
> which button was clicked in your submit function. As #id is built of the
> array key you give the element in the $form variable.

I know that by default they are all named 'op'. This is my problem; I cannot distinguish the buttons by their '#value', because it is always the same. I'm solving this by setting the '#name' to allow me to determine precisely which button was clicked. If I don't set '#name', then *regardless* of which button I press, the 'clicked_button' structure in the $form_state corresponds to the last button of the same '#value' added to the form. Part of the awkwardness here is that HTML doesn't allow you to display some text in a button while having a different value.

Ricky


The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.



More information about the development mailing list