How to create profile when the 3rd step is submitted?

(It looks like user_save do not make user may be because the $form_state I need to do something)

How to preview of what is entered in step 1 and 2
(here sure is a mistake with print but I have not idea how to change to see the preview of step1 and2 in step before submit)

This is the code program :

<?php// $Id:$
function task5_menu() {
$items['user/register'] = array('title' => t('My form'), 'page callback' => 'my_form1', 'access arguments' =>array('access content'), 'description' => t('My form'), 'type' => MENU_CALLBACK,);
return $items;}
function my_form1() {
return drupal_get_form('my_form');}
function my_form(&$form_state) {
$form_values = isset($form_state['values']) ? $form_state['values'] : array();
$step = isset($form_state['storage']['step']) ? $form_state['storage']['step'] + 1 : 1;
$form['#step'] = $step;
$form['#prefix'] = t('Task5');
switch ($step) {
case 1:
$form['fname'] =array('#type' => 'textfield','#title' => t('First Name'),'#size' => 30,
'#maxlength' => 255,'#required' => TRUE,);
$form['name'] = array('#type' => 'textfield','#title' => t('Last Name'),'#size' => 30,
'#maxlength' => 255,'#required' => TRUE,);
$form['mail'] = array('#type' => 'textfield','#title' => t('Email'),'#size' => 30,'#maxlength' => 255,
'#required' => TRUE,);
$form['pass'] = array('#type' => 'textfield','#title' => t('Password'),'#size' => 30,'#maxlength' => 255,
'#required' => TRUE,);
$form['regdate'] = array('#type' => 'date','#title' => 'Date of Birth','#required' => TRUE,);
$form['gender'] = array('#type' => 'radios','#title' => t('Sex'),'#options' => array('1' => t('Male'),'2' => t('Female'),),
'#required' => TRUE,);
$form['education'] = array('#type' => 'textfield','#title' => t('Education'),'#size' => 30,'#maxlength' => 255,);
break;
case 2:
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file_upload'] = array('#title' => t('Picture of yourself'),'#type' => 'file',/* '#required' => TRUE,*/ );
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file_upload2'] = array('#title' => t('CV'),'#type' => 'file', /* '#required' => TRUE,*/);
$form['note'] = array('#type' => 'textfield','#title' => t('Note'),'#size' => 50,'#maxlength' => 255,);
break;
case 3:

/*How to preview of what is entered in step 1 and 2 ?*/

print_r($form_state['values']);
break;}
if ($step < 4) {
$form['submit'] = array( '#type' => 'submit','#value' => t('Next'),); }
$form['step'] = array('#type' => 'value', '#value' => $step, );
return $form;}
function my_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
$form_state['storage']['step'] = $form_state['values']['step'];

/*How to create profile when the 3rd step is submitted ?*/

user_save($account, $form_state['value']);
}

Comments

lorinpda’s picture

Hi,
I have a complete example of a module that allows users to enter a "color" value. After the "color" form is submitted the modules displays a list of user entered colors. All the valid user entries are stored in the database.
.....
You want to add a database "insert" routine during the "submit" phase.
.....
Check out this post:
http://public-action.org/content/drupal-beginners-programming-create-sim...
.....
If you want to find out how I created the custom "my_color" database table, check the previous post here:
http://public-action.org/content/drupal-beginners-programming-creating-s...
.....
Hope that helps.

duckzland’s picture

function my_form_submit(&$form_state) {

      $details = array(
        'name' => $form_state['value']['fname'];
        'pass' => $form_state['value']['pass'];
        'mail' => $form_state['value']['mail'];
        'access' => 0, /* optional, i didnt want user to be able to this this account yet*/
        'status' => 1
      );
     
      $user = user_save(null, $details);

}

try this...

--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com

sergh27’s picture

the code should be easy, and logical should be as you told but I cannot understand why I got:
user warnings: Duplicate entry ....
and the users are not created

jayakrishnanj’s picture

But Password is not storing properly.. It is storing as " d41d8cd98f00b204e9800998ecf8427e " for all kind of passwords..

Please let me know.. where is my fault.

It is importing users from another database :

Following is my code :

module_load_include('inc', 'user', 'user.pages');
db_set_active('mydb');

$pmresult = db_query("SELECT * FROM {user}");
while ($username = db_fetch_object($pmresult)) {
$pmusername= $username->username ;
$pmpassword= $username->password;
db_set_active('default');

include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// Get an array of roles
$roles = user_roles();
print $pmpassword ;
// Basic account information
$account = array(
'name' => $pmusername,
'pass' => $pmpassword,
'mail' => $pmusername,
'status' => 1,
/*'init' => $pmusername,*/
'roles' => array(array_search('customer', $roles) => 1),
);

// See if the user exists by calling Drupal's user_load()
$existing_user = user_load(array('name' => $account['name']));

if (!$existing_user->uid) {

$form_state['values'] = $account;
$form_state['values']['pass'] = array(
'pass1' => $account['pass'],
'pass2' => $account['pass'],
);
$form_state['values']['op'] = t('Create new account');
drupal_execute('user_register', $form_state);
}
}

johnflower’s picture

Why not try the Content Profile module http://drupalmodules.com/module/content-profile

It allows great flexibility in creating registration forms, and would do all the things you are trying to do. It would allows you to create CCK fields for uploading CVs, photos, files, and fields for collecting data.

To get a pretty profile page, you may consider the Advanced Profile Kit module http://drupalmodules.com/module/advanced-profile-kit

sergh27’s picture

There are loosing data in the steps
An idea is to store the form data in the session, create and edit the user every step, or put the data in every form so it keeps posting back.(toddejohnson)

mcaden’s picture

If I remember right from last time I was saving profile values through code...

    $profile_info =  array(
      'profile_fname' => strtolower($form_state['fname'])
    );
  
    profile_save_profile($setProfileWebsite, $account, $category);

setting $category above to be whatever profile category you're using.