Hi,

I'm changing the default log in module, and I want to have the 'Create account'-link to be a button.

I use this:

  $form['actions']['create'] = array('#type' => 'button',
    '#value' => t('Register'),
    '#submit' => array('create_redirect'),
  );

and

function create_redirect() {
  drupal_goto("/user/register");
}

but when I click that button, instead of going to /user/register it goes to /node?destination=node

Comments

webdrips’s picture

@Shadowstep0705, are you trying to completely override the original submit function or add an additional handler? If the latter, you need to change your code to
$form['#submit'][] = 'create_redirect_submit';

If you are only wanting a redirect (that is you have no code before your drupal_goto()), a better option may be
$form_state['redirect'] = 'user/register';

Looking to Migrate from Drupal 6/7 to Drupal 10/11? Have a look at our Drupal 11 demo site and request access.

Chandan Chaudhary’s picture

try changung the button type to submit instead of button

Need Drupal help?
Reach me

Acquia Certified Developer

Backend Frontend and DevOps.

AlexCogn’s picture

By both of them, I get an error message, so I the URL will be /node?destination=node and in the footer there are two error messages:
Error message

Username field is required.
Password field is required.

At first I didn't see them but now I do. Ofcourse these two should be required when pressing the 'create' button

AlexCogn’s picture

I want an additional redirect, which will be activated when clicking a second button. The main submit button will stay.

Chandan Chaudhary’s picture

yeh you can have multiple button on a single from but if u are providing the submit handler for and element then the type of that button should be submit

Need Drupal help?
Reach me

Acquia Certified Developer

Backend Frontend and DevOps.

AlexCogn’s picture

What would be the point of implementing a button if you can't specify any handler for it?

Chandan Chaudhary’s picture

its a simple concept buddy u can't submit a form on click of a element button to get the form submitted u have to specify element type as submit . in case of button u can invoke a javascript function that will submit ur fourm using javascript method submit

or else if u want to simply redirect to register page u can define anchor tag to do that rather than having a button there

Need Drupal help?
Reach me

Acquia Certified Developer

Backend Frontend and DevOps.

webdrips’s picture

I think you just need to add the following to your array:
'#executes_submit_callback' => TRUE,

Looking to Migrate from Drupal 6/7 to Drupal 10/11? Have a look at our Drupal 11 demo site and request access.

AlexCogn’s picture

Doesn't work

webdrips’s picture

Can you re-post your form code as-is right now?

Looking to Migrate from Drupal 6/7 to Drupal 10/11? Have a look at our Drupal 11 demo site and request access.

webdrips’s picture

OK, I had to try it out for myself to see that both the required fields and authentication validation were causing issues, so I came up with something that worked:

  $form['actions']['create'] = array(
    '#type' => 'button',
    '#value' => t('Register'),
    '#attributes' => array('onClick' => 'location.replace("/user/register"); return false;'),
  );

Looking to Migrate from Drupal 6/7 to Drupal 10/11? Have a look at our Drupal 11 demo site and request access.