On my site, I want to have users register accounts through the web interface, not through Drupalgap, because I have a fairly complicated registration flow.
However, the link on the user login form includes a "register an account" button that links to user/register.
I tried the following code in mymodule_form_alter():
if (form_id == 'user_login_form') {
form.elements.name.title = 'E-mail address';
form.elements.submit.value = 'Login';
form.buttons.create_new_account.title = 'Create a free account';
form.buttons.create_new_account.path = 'http://mysite.com/en/user/register';
form.buttons.create_new_account.attributes.onclick = ""';
form.buttons.create_new_account.attributes.InAppBrowser = true;
}
}
Here is a dpm() of the register button when generated with the above code:
"buttons": {
"create_new_account": {
"attributes": {
"InAppBrowser": true,
"onclick": ""
},
"path": "http://mysite.com/en/user/register",
"title": "Create a free account"
}
},
However, this doesn't work. I think this is because the onclick is set to NULL, when it should be removed entirely, but I don't know how to do that.
I tried to remove the onclick by modifying attributes in hook_form_alter() like this:
form.buttons.create_new_account.attributes.onclick = ""';
form.buttons.create_new_account.attributes.InAppBrowser = true;
However, if I do this, the InAppBrowser part never appears (dpm output):
"buttons": {
"create_new_account": {
"attributes": "",
"path": "http://mysite.com/en/user/register",
"title": "Create a free account"
}
},
How can I use hook_form_alter() to override the path of the register button?
Comments
Comment #1
ptmkenny CreditAttribution: ptmkenny commentedComment #2
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedMaybe try appending something to the suffix of the form instead:
form.suffix += bl('Create a free account', 'http://mysite.com/en/user/register', { InAppBrowser: true });
Comment #3
ptmkenny CreditAttribution: ptmkenny commentedPerfect, that did it. I set the buttons to null to hide the old one and added in the new one like this: