How to create a new user with the multipageform custom Drupal module

I had a question about a tutorial that I saw on sitepoint.com
http://www.sitepoint.com/building-multi-page-wizard-like-form-drupal/

I’ve got everything in the custom module and now I need to know how to go about actually creating the user using this form.

The multipageform_form1_submit code where you said //Store the values from $finalformvalues in database or file etc

What am I to do to actually create a new user? I’m sure that little snippet of code needs to change but I just don’t know what to change. Any help would be greatly appreciated. Thanks in advance.

Hi whiteOwl, welcome to the forum,

I’m not very familliar with using Drupal, but
//Store the values from $finalformvalues in database or file etc
is a comment that indeed indicates that code needs to be added there.

What code gets added will depend on what you want to do, the “database or file etc” part.

IMHO a good place to start would be to find out what information is available to be stored and what format it’s in to be worked with. i.e. temporarily try adding

            $currStep++;
        }
        //Store the values from $finalformvalues in database or file etc
var_dump($finalformvalues);
    }

If that works, please post what you see.

Placing that code in there just took me back to the 1st part of the form. Here’s a link to my module http://partypalaceplus.com/multipageform.zip

You’d want to unzip it and look at the file named multipageform.module

I’d like this form to ultimately save a new user to the database, and thank you for your reply. Hope you can help me out here. I’ll keep working on it and let you know if I come up with a solution.

Also, don’t know if this would help but code for a registration form from my Drupal site looks like this

enter link description here

Thanks, that’s some help.

Do you know what happens at

action="/beta/user/personal_information"

Do you know how you want to store the data? eg.
database
CSV file
XML file
other?

It would ultimately store the new user in the database. I don’t “know” what happens upon the action, I gave you the code to a registration form from my site above - here it is again
link-to-exisiting-registration-form

I got the registration form OK. What I’m interested in is what happens when it gets to where it’s sent.
The action attribute value is where the inputs are sent as $_POST (the “method” value) variables.
Do you know what’s at
/beta/user/personal_information

Here’s the code from that pages form
download text file here

OK, I’m missing something here.
That form is at /beta/user/personal_information
and sends the form data to /beta/user/personal_information

Unless something is going on with the relative paths (routing trickery?) that means that the personal_information folder contains a beta folder i.e.
/beta/user/personal_information//beta/user/personal_information

:confused:

Beginning slash would mean from the root. So it should be sending the data back to itself.

I found this tutorial that may shed some light on what I’d need to place within my module I created in order to actually create a new user
link to another tutorial

I’d like to mention that I also built a module from the above mentioned tutorial and when I
upload it to my site my site becomes just a white blank screen. You can
download the module I built following that tutorial here

:d’oh: Thanks, I missed that. I’m in the habit of using “#”

I found something about the submit function here. I will test some things out and let you know my findings. If anyone else knows of a way to get what I need done feel free to share. Thanks in advance.

I have no idea as to what I need to do. Anybody have a clue?

Only a wild guess at best without knowing what you have to work with. Take out the var_dump line and try

        foreach (getForm() as $step) {
            foreach ($step as $key => $value) {
                if(strcmp($key,"submit") != 0) {
                    $finalformvalues[$key] = $form_state['storedvalues'][$currStep][$key];
                }
            }
            $currStep++;
        }
        //Store the values from $finalformvalues in database or file etc

$handle = fopen("registration-form-test.csv", "wb");
foreach ($finalformvalues as $fields) {
	fputcsv($handle, $fields);
}
fclose($handle);
// end test code section

}

Then find the registration-form-test.csv file and post what’s in it.

I did what you said and at the end of the form process I received this error

Warning: fputcsv() expects parameter 2 to be array, string given in multipageform_form1_submit() (line 127 of /fullSitePathHere/beta/modules/multipageform/multipageform.module).

You can download my updated module here with your modified code. By the way, I’d ultimately like to save this user to the database thus creating a new user.

After looking at this page some more it dawned on me maybe I should try this

foreach (getForm() as $step) {
foreach ($step as $key => $value) {
if(strcmp($key,“submit”) != 0) {
$finalformvalues[$key] = $form_state[‘storedvalues’][$currStep][$key];
}
}
$currStep++;
}
//Store the values from $finalformvalues in database or file etc
user_save(drupal_anonymous_user());
}
}

But then I received this error

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘’ for key ‘name’: INSERT INTO {users} (uid, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 73 [:db_insert_placeholder_1] => 1415857711 ) in drupal_write_record() (line 7202 of /fullSitePathHere/beta/includes/common.inc).

I’m going to add username and email as fields to this test form within the module and see what happens.

That didn’t help. I’m reading up on this other page now about saving user accounts within Drupal via a module

Ideally it will be very nice to find an existing Drupal function that will do what you need without requiring any (or much) custom code to be written.

As I said, I have very little experience with Drupal so I’m struggling along trying what I’d try with basic PHP code.

Try this instead of the previous

        foreach (getForm() as $step) {
            foreach ($step as $key => $value) {
                if(strcmp($key,"submit") != 0) {
                    $finalformvalues[$key] = $form_state['storedvalues'][$currStep][$key];
                }
            }
            $currStep++;
        }
        //Store the values from $finalformvalues in database or file etc


$handle = fopen("registration-form-test.csv", "wb");
//foreach ($finalformvalues as $fields) {
//	fputcsv($handle, $fields);
	fputcsv($handle, $finalformvalues);
//}

fclose($handle);
// end test code section

}