By kendre_paresh on
Hello All,
Please tell how can i add "Cancel" button in user registration form?
I have added it in function user_register() {} function, but the cancel button is moving above the user registration field set, and "Create New Account" button is below the fieldset.
How can place these two i one line, below the fieldset.
I have added prefix and suffix aswell.
$form['submit'] = array('#type' => 'submit', '#value' => t('Create New Account'), '#weight' => 30, '#prefix' => '<div class=userregButton>');
$form['cancel'] = array('#type' => 'button', '#value' => t('Cancel'), '#suffix' => '</div>' );
Please help.
Comments
Hi, i had a similar problem,
Hi,
i had a similar problem, and i have solved using the type 'markup' and inserting a html button and the "onclick" javascript function for a callback.
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Sned'),
);
$form['cancel'] = array(
'#type' => 'markup',
'#value' => ''
);
The 2 button now are on the same line.
I hope this will be usefull.
If anyone has a better idea, write here :-D
Aran
Nooo, It simply give me the
Nooo,
It simply give me the label "Cancel", and again on the top of the page, not beside the "Create New Account".
I have done in this way
Thanks n regards,
Paresh Kendre.
Weight it
Try giving it a weight as such:
Great, It works for me,
Great,
It works for me, thank you so much! :)
Thanks n regards,
Paresh Kendre.
Can any one help me out i
Can any one help me out i need 'Cancel' button .
onclick cancel button-
1) session must destroy and
2) Redirect to home page ie drupa_goto()
For that i added below code its working fine for session destroy, but how could i redirect to home page ie drupal_goto()
$form['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('onClick' => session_destroy()),
'#weight' => 1002,
);
after this how could i redirect .
Thanks in advance.
have you tried this
have you tried this one?
$form['cancel'] = array(
'#type' => 'button',
'#value' => t('Cancel'),
'#attributes' => array('onClick' => 'session_destroy(); drupal_goto("pathOfIndexPage")'),
'#weight' => 1002,
);
try to add the actions in quotes separated with semicolon(;)
try it.
Thanks n regards,
Paresh Kendre.
Hi
$form['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#attributes' => array('onclick' => 'window.location = '. base_path() .'; return false; ', session_destroy()),
'#weight' => 1002,
);
---------------------
i tried this ,and i am successful for both session close and redirect to front page.
ok. Thanks n regards, Paresh
ok.
Thanks n regards,
Paresh Kendre.
Cancel button
Drupal 7 solution.
Work for me :)))
Good Luck
In case of normal cancel button in a form
$form['actions']['cancel'] = ['#type' => 'submit','#value' => $this->t('Cancel'),'#button_type' => 'primary','#attributes' => ['onClick' => 'javascript:window.history.go(-1); return false;'],];