Greetings,
I noticed the following problem which was in Drupal 5.0 and looks still not fixed.
After I changed a text on "Create new account" button to any other text using form_alter hook (ex: "Register now") admin/user/user/create form stopped to function properly - it doesn't do anything. However, user/register form works.
It is quite a critical defect because in 9 of 10 projects clients are not satisfied with default "Create new account" text and would like to change it to something else.
The problem looks to be common - in some cases changing button text breaks form which is bad because form functioning should not be tied with text on the button.
Thanks.
Comment | File | Size | Author |
---|---|---|---|
#28 | 208790_user_admin_28.patch | 4.84 KB | trrroy |
#24 | 208790_user_admin_2.patch | 4.83 KB | theborg |
#23 | 208790_user_admin.patch | 4.83 KB | theborg |
#21 | 208790_and_tests.patch | 13.56 KB | theborg |
#19 | 208790_user_admin.patch | 4.42 KB | theborg |
Comments
Comment #1
catchWhy not use the language system or settings.php string array (which is new) to do this?
Comment #2
theborg CreditAttribution: theborg commentedAgree with @catch but hardcoding parameters is not the way to go.
This patch eliminates the
t('Create new account')
and t('Search') from user_admin function. I tested and it works but more testing is needed to verify that not affects other functionality.Comment #3
theborg CreditAttribution: theborg commentedComment #4
Gábor HojtsyWell, this would be quite a paradigm shift for Drupal form flows. We have this kind of op = t() check all over the place.
Comment #5
ardas CreditAttribution: ardas commentedThis patch looks clever for me. I don't understand why Drupal authors didn't implement this from the beginning.
Comment #6
ardas CreditAttribution: ardas commentedUsing button caption to determine which button was pressed is a completely bad idea.
This breaks one of the fundamental programming principle - variable data (especially UI data) should not be used as a key data for functionality.
A button must have a permanent key (internal short name, no spaces, no capital letters, etc.) which should be used in the code.
Does it make sence?
Comment #7
Gábor HojtsyYes, it makes sense, and it would be great to clean it up in Drupal 7. Unfortunately this is such a paradigm shift for core that it is late to do it right now in Drupal 6. We risk introducing numerous new bugs. Until then, you can try nasty tricks to put back the original button title in a custom validation callback. (I never tried but I'd expect that it works).
Comment #8
ardas CreditAttribution: ardas commentedSure, no problem.
I would be glad to see this fix in Drupal 7.
Thanks :)
Comment #9
birdmanx35 CreditAttribution: birdmanx35 commentedThis patch fails against core, so I am setting it to code needs work.
Comment #10
bryan kennedy CreditAttribution: bryan kennedy commentedI just wanted to put in my vote for this fix. While the language system is the ideal, many regular drupal users can't afford the overhead to turn that on and need to resort to theming to control the display of form elements like this.
I would really appreciate seeing this fix in the core at some point in the future.
Comment #11
Damien Tournoud CreditAttribution: Damien Tournoud commentedUsing hook_form_alter() or the theming system to change that is *not* the way to go.
You will want to use the language system (which don't require enabling the locale module at all) to change the strings. One easy way to do this is by using the String Overrides module, but you can also override strings from your settings.php file.
Given this, this is probably a non-bug.
Comment #12
AaronBaumanJust because there is a work-around (installing a module or updating settings.php) doesn't mean that this is a non-bug.
Changing the text of a button, whether through hook_form_alter or the theming system, should not break a form's functionality. This issue addresses the fundamentally bad practice of mixing the logic and UI layers.
Count this as my vote for a Drupal-wide fix.
Comment #13
honorfield CreditAttribution: honorfield commentedThe "String Overrides modul" worked fine for me in Drupal 6.15. I could easily change the "Create new account" text with my own text:)
Thanks for the suggestion Damien. Although it is very annoying that i have to install a module to change the text of a tab!
Comment #14
Agileware CreditAttribution: Agileware commentedAny chance this could be revisited?
As mentioned in multiple places around drupal.org, op shouldn't be relied on.
For a good example of this see http://drupal.org/node/144132#op
Also, I have not seen anywhere any doco that says you can use form alter to modify forms, but whatever you do don't modify the text on form submit buttons as it might break your sites functionality.
It just isn't intuitive.
Would this work as a solution or would it cause issues?
Comment #15
tinny CreditAttribution: tinny commentedbump. i have the same problem. d6
i tried:
$form['submit']['#value'] = t('Add company');
user/register works but not admin/user/user/create (it takes me back to list users)
currently using string overrides as a work around...
Comment #16
scor CreditAttribution: scor commentedsubscribe. we need to remove this old cruft, though it'll have to be fixed in D8 first.
I would be tempted to remove this line of code:
from user_admin() and just rely on the callback argument. There is only one place in core where this op value seems to be used: openid.module.
Comment #17
adnanhader CreditAttribution: adnanhader commentedI have used a very simple technique using CSS to override create new account button with my custom button image with required text on it. hook_form_alter of course involved in it. just use
This way i have assigned a new class to create new account button. implement button image into input.create_account class. you can hide create new account / default text in this class.
Comment #18
AaronBaumanComment #19
theborg CreditAttribution: theborg commentedThe 'problem' still persists in d8-dev.
One possible solution for this issue and the rest of modules could be using
$form_state['triggering_element']['#name']
that forms module is populating with the clicked button.To do that:
1. Add a name attribute to all the buttons that needs checking.
2. Change the logic to avoid the use of
t()
in conditional code.3. Update tests without language dependence.
Don't know if these changes also affect performance, in a positive way.
Comment #21
theborg CreditAttribution: theborg commentedNew patch with tests updated.
Comment #23
theborg CreditAttribution: theborg commentedRetesting first #19 patch, updated user.module to add a named to 'Create new account' button.
Comment #24
theborg CreditAttribution: theborg commentedComment #25
theborg CreditAttribution: theborg commentedIncluded in: http://drupal.org/node/1279688
Comment #26
czigor CreditAttribution: czigor commentedThis appliies and works great on D7.
Comment #27
sinasalek CreditAttribution: sinasalek commentedGreat, we definitely need this for Drupal 7. field_group_ajaxified_multipage depends on this patch for some of it's functionality to work.
Comment #28
trrroy CreditAttribution: trrroy commentedThis is the same patch as #24 but re-rolled for D7.22 and it's working for me.
Comment #30
steveoliver CreditAttribution: steveoliver commentedLet's see if it'll apply against 7.x
Comment #31
steveoliver CreditAttribution: steveoliver commented#28: 208790_user_admin_28.patch queued for re-testing.
Comment #32
steveoliver CreditAttribution: steveoliver commentedThe proposal of this issue is sane. It allows submit buttons to display whatever
#value
is needed without breaking form submit functionality. It keeps developers from needing to implement additional#validate
or#submit
handlers to work around the unnecessary use oft()
.However, as noted in #4 and #7, this will surely cause issues for numerous d7 sites, given the existing checks of
$form_state['values']['op'] == t()
, including the core example indrupal_form_submit()
to set this value when programatically submitting forms.So unfortunately, I see no way for this to make it into 7.x core at this point.
This is a bug, so a working patch will probably make it into 8.x (as scor pointed out in #16).
Comment #33
mgiffordComment #34
erdjordje CreditAttribution: erdjordje commentedI tested this problem in 8.x and it seems that the problem is fixed.
I used following code in hook_form_alter to change name of the button.
Comment #37
dpiThe form API changed considerably. The following code is longer an issue on Drupal 8:
But I agree with #1 that the language system can be used for this: https://www.drupal.org/docs/7/howtos/change-default-strings-text-without...
Changing to 7.x
Comment #38
anrikun CreditAttribution: anrikun commentedHere's a workaround in the meantime.
In a custom module (called
custom_user
in example below), add:This should solve all this WTF.