membership webform submit fill cart then redirect to checkout, HO YEAH
This commit is contained in:
		@@ -182,11 +182,12 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // if( $form_id == "webform_client_form_11186" ){
 | 
			
		||||
  # https://drupal.org/comment/6293810#comment-6293810
 | 
			
		||||
  if( $form_id == "webform_client_form_11186" ){
 | 
			
		||||
    // dsm($form, '$form');
 | 
			
		||||
    // $form['#validate'][] = "materio_user_webform_client_111186_validate";
 | 
			
		||||
    // $form['#submit'][] = "materio_user_webform_client_111186_submit";
 | 
			
		||||
  // }
 | 
			
		||||
    $form['#validate'][] = "materio_user_webform_client_11186_validate";
 | 
			
		||||
    $form['#submit'][] = "materio_user_webform_client_11186_submit";
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  // if( $form_id == "user_profile_form" ){
 | 
			
		||||
@@ -226,9 +227,11 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
 | 
			
		||||
//   );
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
function materio_user_webform_client_111186_validate($form, &$form_state){
 | 
			
		||||
function materio_user_webform_client_11186_validate($form, &$form_state){
 | 
			
		||||
  // dsm($form, 'form');
 | 
			
		||||
  // dsm($form_state, 'form_state');
 | 
			
		||||
 | 
			
		||||
  # test if collaborators are filled in case of membership option is 3
 | 
			
		||||
  $values = $form_state['values']['submitted'];
 | 
			
		||||
  if ($values['column_left']['membership_options'] == 3) {
 | 
			
		||||
    foreach ($values['collaborators'] as $coll_key => $coll) {
 | 
			
		||||
@@ -240,57 +243,72 @@ function materio_user_webform_client_111186_validate($form, &$form_state){
 | 
			
		||||
 | 
			
		||||
          // TODO : tester si les email ne sont pas deja inscrit sur le site
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
          form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));      
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
  } 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// function materio_user_webform_client_111186_submit($form, &$form_state){
 | 
			
		||||
//   dsm($form, 'form');
 | 
			
		||||
//   dsm($form_state, 'form_state');
 | 
			
		||||
//   $values = $form_state['values']['submitted_tree'];
 | 
			
		||||
//   if ($values['membership_options'] == 3) {
 | 
			
		||||
//     $i = 1;
 | 
			
		||||
//     foreach ($values['collaborators'] as $coll_key => $coll) {
 | 
			
		||||
//       // foreach ($coll as $field_key => $field_value) {
 | 
			
		||||
//       //   if($field_value == ''){
 | 
			
		||||
//       //     $human_field_name = $form['submitted']['collaborators'][$coll_key]['#title'] . " : " . $form['submitted']['collaborators'][$coll_key][$field_key]['#title'];
 | 
			
		||||
//       //     $field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
 | 
			
		||||
//       //     // dsm($field_name, 'field_name');
 | 
			
		||||
function materio_user_webform_client_11186_submit($form, &$form_state){
 | 
			
		||||
  // dsm($form, 'form');
 | 
			
		||||
  // dsm($form_state, 'form_state');
 | 
			
		||||
  $values = $form_state['values']['submitted_tree'];
 | 
			
		||||
 | 
			
		||||
//       //     form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));      
 | 
			
		||||
//       //   }
 | 
			
		||||
//       // }
 | 
			
		||||
//       $userinfo = array(
 | 
			
		||||
//         'mail' => $coll['e_mail_collab_'.$i],
 | 
			
		||||
//         'name' => user_password(),
 | 
			
		||||
//         'pass' => user_password(), // Generate password
 | 
			
		||||
//         // 'init' => $data['components']['username']['value'],
 | 
			
		||||
//         'status' => 0,
 | 
			
		||||
//         'access' => REQUEST_TIME,
 | 
			
		||||
//         'memo' => 'from webform',
 | 
			
		||||
//       );
 | 
			
		||||
//       $account = drupal_anonymous_user();
 | 
			
		||||
//       $account->is_new = TRUE;
 | 
			
		||||
//       user_save($account, $userinfo);
 | 
			
		||||
//       // module_invoke_all('user_insert', $edit, $account);
 | 
			
		||||
//       $i++;
 | 
			
		||||
//     }
 | 
			
		||||
    
 | 
			
		||||
  # redirect memebership form to checkout with good option selected
 | 
			
		||||
  
 | 
			
		||||
  $subscription_level = 3;//$values['membership_options'];
 | 
			
		||||
 | 
			
		||||
//   } 
 | 
			
		||||
  // to redirect to 'node/123?foo=bar#baz':
 | 
			
		||||
  // http://www.ubercart.org/node/1427
 | 
			
		||||
  $form_state['redirect'] = array(
 | 
			
		||||
    'cart/add/e-p11786_q1_a1o'.$subscription_level.'-membershipform',
 | 
			
		||||
    array(
 | 
			
		||||
      'query' => array(
 | 
			
		||||
        'destination' => 'cart/checkout',
 | 
			
		||||
      ),
 | 
			
		||||
      // 'fragment' => 'baz',
 | 
			
		||||
    ),
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
# create collaborators users account incase of membership option is 3
 | 
			
		||||
/*
 | 
			
		||||
  if ($values['membership_options'] == 3) {
 | 
			
		||||
    $i = 1;
 | 
			
		||||
    foreach ($values['collaborators'] as $coll_key => $coll) {
 | 
			
		||||
      // foreach ($coll as $field_key => $field_value) {
 | 
			
		||||
      //   if($field_value == ''){
 | 
			
		||||
      //     $human_field_name = $form['submitted']['collaborators'][$coll_key]['#title'] . " : " . $form['submitted']['collaborators'][$coll_key][$field_key]['#title'];
 | 
			
		||||
      //     $field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
 | 
			
		||||
      //     // dsm($field_name, 'field_name');
 | 
			
		||||
 | 
			
		||||
      //     form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));      
 | 
			
		||||
      //   }
 | 
			
		||||
      // }
 | 
			
		||||
      $userinfo = array(
 | 
			
		||||
        'mail' => $coll['e_mail_collab_'.$i],
 | 
			
		||||
        'name' => user_password(),
 | 
			
		||||
        'pass' => user_password(), // Generate password
 | 
			
		||||
        // 'init' => $data['components']['username']['value'],
 | 
			
		||||
        'status' => 0,
 | 
			
		||||
        'access' => REQUEST_TIME,
 | 
			
		||||
        'memo' => 'from webform',
 | 
			
		||||
      );
 | 
			
		||||
      $account = drupal_anonymous_user();
 | 
			
		||||
      $account->is_new = TRUE;
 | 
			
		||||
      user_save($account, $userinfo);
 | 
			
		||||
      // module_invoke_all('user_insert', $edit, $account);
 | 
			
		||||
      $i++;
 | 
			
		||||
    }
 | 
			
		||||
  } 
 | 
			
		||||
*/
 | 
			
		||||
  // enregistrer le type d'adonnement chez les user
 | 
			
		||||
 | 
			
		||||
// }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Implements hook_help().
 | 
			
		||||
 */
 | 
			
		||||
*/
 | 
			
		||||
function materio_user_help($path, $arg) {
 | 
			
		||||
  // dsm($path, 'path');
 | 
			
		||||
  // dsm($arg, 'arg');
 | 
			
		||||
@@ -315,7 +333,6 @@ function materio_user_help($path, $arg) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Implements hook_block_view_alter().
 | 
			
		||||
 */
 | 
			
		||||
@@ -327,7 +344,6 @@ function materio_user_block_view_alter(&$data, $block) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Define constants
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user