Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm doing a bunch of work porting the Protoype ajax system to work on Drupal. Many of the functions will need to target the "form" element.
Maybe I'm missing something, but it looks like the form_id in drupal_get_form('form_id', &$form, $callback)
doesn't actually make it into the form
tag. Instead it ends up in <input type="hidden" name="edit[form_id]" value="form_id" />
, but doesn't actually define an id of anything on the page.
Shouldn't this form_id be the id of the form element?
-Jeff
Comment | File | Size | Author |
---|---|---|---|
#3 | form_id_1.patch | 1.09 KB | chx |
#2 | form_id_0.patch | 10.74 KB | chx |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedthis is still happenning . i agree that this is not intended behavior. anyone from form api team able to comment?
Comment #2
chx CreditAttribution: chx commentedThis is our (== Adrian & I) intended behaviour, but I can see how people would expect what jjeff describes, so here is a patch.
Comment #3
chx CreditAttribution: chx commentedComment #4
Dries CreditAttribution: Dries commentedCan't we write:
instead of:
Why do we need two ways to set the idea?
Comment #5
chx CreditAttribution: chx commentedOnce again the naming causes confusion. Too many good words are already used by HTML, and while we have renamed post_process to after_build I do not see right what would be a good for a parameter which identifies the form for Drupal. It is not a DOM identifier for HTML, no. It is possible for whatever reason that $form['#id'] , the DOM identifier differs from $form_id which is the Drupal form identifier.
Comment #6
jjeff CreditAttribution: jjeff commentedI would have written it the way you did, CHX.. But upon further thinking about Dries' response, isn't it the same module that defines
$form['form_id']
as defines$form['#attributes'] = array('id' => 'form_id');
?In other words isn't the purpose of both of these basically the same: to give the form an identifier? And isn't this definition made in one place: the module?
So I think it's probably safe to assume that
...of course as a developer, I would probably be very confused if/when my
$form['#attributes'] = array('id' => 'form_id');
got reset and didn't make it to the page...So I could certainly go either way on this one and it's definitely safer to go with CHX's method, but Dries has a good point.
-Jeff
Comment #7
chx CreditAttribution: chx commentedNot so. Let's state this again: $form['form_id'] is a critical element of the form API's inner working, because that'll let it know which form has been submitted. Therefore we overwrite this element without mercy. Form API , on the other hand does not depend on $form['#id'] and it being the ever-extendable one, I do not see why we should not let ppl set their own #id if they want.
Comment #8
jjeff CreditAttribution: jjeff commentedOkay CHX, you've won me over. :-)
+1 CHX
-jeff
Comment #9
Crell CreditAttribution: Crell commentedI can't think of a reason why someone would want $form['#id'] != $form['form_id'], but I can't see where permitting it causes any immediate problems, either. So +1 to the patch in #3 from me as well.
Comment #10
adrian CreditAttribution: adrian commented+1 on the form_id.
It's very useful information for themers.
Comment #11
Steven CreditAttribution: Steven commentedCommitted to HEAD.
Comment #12
(not verified) CreditAttribution: commented