OK so this is my hook form alter function.It is causing all the registration forms on site to be over written which I do not want as I just want it on this page.
function special_registration_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_register') {
drupal_set_title(t('Custom registration'));
$form['firstname'] = array('#type' => 'textfield',
'#title' => t('First Name: *'),
'#required' => TRUE,
'#size' => 45,
'#weight' => - 100,);
$form['lastname'] = array('#type' => 'textfield',
'#title' => t('Last Name: *'),
'#required' => TRUE,
'#size' => 45,
'#weight' => - 99,);
}
I only first name and last name to be captured and stored in a different table just on this page.
On other pages I just want the good old fashioned form. Do I still need to change the weight? I know I am missing something elementary.
You just need a check for the current page, using either arg or $_GET['q'].
eg:
function special_registration_form_alter(&$form, $form_state, $form_id) {
if ($_GET['q'] !== 'whatever/path' ) { return false; }
..rest of code..
}
If you want to restrict your form alterations to a specific page, you can simply add a check for the page to your form id check, e.g.:
function special_registration_form_alter(&$form, $form_state, $form_id) {
// Alter the registration form, but only on 'user/register' pages
if ($form_id == 'user_register' && 'user' == arg(0) && 'register' == arg(1)) {
// snipped alteration code
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With