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

ptmkenny’s picture

Issue summary: View changes
tyler.frankenstein’s picture

Maybe 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 });

ptmkenny’s picture

Status: Active » Fixed

Perfect, that did it. I set the buttons to null to hide the old one and added in the new one like this:

        form.buttons = '';
        form.suffix += bl('Create a free account', base_url + '/en/user/register', { InAppBrowser: true });

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.