Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. function add_new_article_simple_page() {
  2. module_load_include('inc', 'node', 'node.pages');
  3. $node_form = new stdClass;
  4. $node_form->type = 'announcement';
  5. $node_form->language = LANGUAGE_NONE;
  6. $form = drupal_get_form('announcement_node_form', $node_form);
  7. return $form;
  8. }
  9.  
  10. function add_new_article_form_alter(&$form, &$form_state, $form_id){
  11. if($form_id=='announcement_node_form')
  12. {
  13. $form['#after_build'][] = 'add_new_article_after_build';
  14. $form['account_password'] = array(
  15. '#title' => 'Parola',
  16. '#type' => 'password',
  17. '#required' => TRUE,
  18. );
  19. $form['#submit'][] = 'add_new_article_form_submit';
  20.  
  21. return $form;
  22. }
  23. }
  24.  
  25. function add_new_article_form_submit($form, &$form_state){
  26. $email=$form_state['values']['field_email']['und'][0]['value'];
  27. $password=$form_state['values']['account_password'];
  28. //check if the email even exists
  29. if(!db_query("SELECT COUNT(*) FROM {users} WHERE name = '".$email."';")->fetchField())
  30. //create the new account
  31. {
  32. $edit = array(
  33. 'name' => $email,
  34. 'pass' => $password,
  35. 'mail' => $email,
  36. 'init' => $email,
  37. 'roles' => array('4' => 'standard user'),
  38. 'status' => 0,
  39. 'access' => REQUEST_TIME,
  40. );
  41. $loc_var=user_save(drupal_anonymous_user(), $edit);
  42. $GLOBALS['new_user']=$loc_var->uid;
  43. }
  44. else
  45. {
  46. //check if username + password are valid combination
  47. if($uid = user_authenticate($email,$password))
  48. //log in user after account creation
  49. else
  50. //this is where I want to interrupt the submission of the form
  51. form_set_error('account_password', 'Parola nu este buna pentru acest email.');
  52. }
  53. }
  54.  
  55. function add_new_article_form_validate($form, &$form_state)
  56. {
  57. $email=$form_state['values']['field_email']['und'][0]['value'];
  58. $password=$form_state['values']['account_password'];
  59. form_set_error('account_password',t('The form is being validated.'.$email.' and '.$password));
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement