How to override a form on only one page?

OK, so this is my hook shape change function. This leads to the fact that all registration forms on the site will be written in an inscription that I do not want, because 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 need a good old fashioned uniform. Do I still need to change weight? I know that I am missing something basic.

+6
php drupal drupal-6 drupal-fapi
source share
5 answers

You just need to check the current page using 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.. } 
+2
source share

If you want to limit form changes to a specific page, you can simply add validation to validate your form, for example:

 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 } } 
+2
source share

You can also use the profile module in the main list of modules. This will solve it without any programming, fyi.

0
source share

hook_user() ; the function allows you to change the form submitted to users when registering on the site. hook_user() used by the user .module and is independent of the profile module.

Defining the hook as hook_user($op, &$edit, &$account, $category = NULL) , the $op parameter will contain the value 'register' when the registration form is presented to the user. In this case, the module returns the form fields that it wants to add to the registration form.

0
source share

If you really do not need to create user accounts, for example, for a simple registration of events. If instead you only collect names, you can use the webform module.

0
source share

All Articles