Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function company_form()
- {
- $form['company_username'] = array(
- '#type' => 'textfield',
- '#title' => 'company-username',
- '#default_value' => '',
- '#required'=>'true'
- );
- $form['company_email'] = array(
- '#type' => 'textfield',
- '#title' => 'company-email',
- '#required'=>'true',
- '#default_value' => '',
- '#element_validate' => array('generate_special_form_validate'),
- );
- $form['company_password'] = array(
- '#type' => 'textfield',
- '#title' => 'company-password',
- '#required'=>'true',
- '#default_value' => ''
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#title' => '',
- '#value' => 'Submit',
- '#default_value' => ''
- );
- return $form;
- }
- function company_form__validate(&$form_state,$form) {
- if (!valid_email_address($form['input']['email'])) {
- form_set_error($form['input']['email'],'Please enter a valid email address.');
- }
- }
- function company_form_submit($form, &$form_state)
- {
- global $user;
- $company_username = $form_state['input']['company_username'];
- $company_email = $form_state['input']['company_email'];
- $company_password = $form_state['input']['company_password'];
- $fields = array(
- 'name' => $company_username,
- 'pass' =>$company_password,
- 'mail' => $company_email,
- 'init' => $company_email,
- 'status' => 1,
- 'access' => REQUEST_TIME,
- 'roles' => array(
- 4 => 'company',
- ),
- );
- $account=user_save('', $fields);
- if($account->uid)
- {
- drupal_set_message('User Created SuccessFully');
- }
- }
- 'roles' => array(
- 4 => 'company',
- ),
- /**
- * Implements hook_form_BASE_ID_alter()
- */
- function CUSTOM_MODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
- // Get the system roles.
- $roles = array_map('check_plain', user_roles(TRUE));
- $form['roles'] = array(
- '#type' => 'select',
- '#title' => t('Roles'),
- '#default_value' => array(),
- '#options' => $roles,
- );
- }
- /**
- * Implements hook_user_insert()
- */
- function CUSTOM_MODULE_user_insert(&$edit, $account, $category) {
- // Save the role if it's set.
- if (isset($edit['roles'])) {
- // Push the roles to $account object so that user_save can get the role property.
- $account->roles[] = $edit['roles'];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement