Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add_new_article_simple_page() {
- module_load_include('inc', 'node', 'node.pages');
- $node_form = new stdClass;
- $node_form->type = 'announcement';
- $node_form->language = LANGUAGE_NONE;
- $form = drupal_get_form('announcement_node_form', $node_form);
- return $form;
- }
- function add_new_article_form_alter(&$form, &$form_state, $form_id){
- if($form_id=='announcement_node_form')
- {
- $form['#after_build'][] = 'add_new_article_after_build';
- $form['account_password'] = array(
- '#title' => 'Parola',
- '#type' => 'password',
- '#required' => TRUE,
- );
- $form['#submit'][] = 'add_new_article_form_submit';
- return $form;
- }
- }
- function add_new_article_form_submit($form, &$form_state){
- $email=$form_state['values']['field_email']['und'][0]['value'];
- $password=$form_state['values']['account_password'];
- //check if the email even exists
- if(!db_query("SELECT COUNT(*) FROM {users} WHERE name = '".$email."';")->fetchField())
- //create the new account
- {
- $edit = array(
- 'name' => $email,
- 'pass' => $password,
- 'mail' => $email,
- 'init' => $email,
- 'roles' => array('4' => 'standard user'),
- 'status' => 0,
- 'access' => REQUEST_TIME,
- );
- $loc_var=user_save(drupal_anonymous_user(), $edit);
- $GLOBALS['new_user']=$loc_var->uid;
- }
- else
- {
- //check if username + password are valid combination
- if($uid = user_authenticate($email,$password))
- //log in user after account creation
- else
- //this is where I want to interrupt the submission of the form
- form_set_error('account_password', 'Parola nu este buna pentru acest email.');
- }
- }
- function add_new_article_form_validate($form, &$form_state)
- {
- $email=$form_state['values']['field_email']['und'][0]['value'];
- $password=$form_state['values']['account_password'];
- form_set_error('account_password',t('The form is being validated.'.$email.' and '.$password));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement