By flamingvan on
A client of mine wanted to have multiple registration pages with different fields so I wrote this script. I'm sure it would have been better to make a module but I don't really know how. Anyone want to help?
Here's how it works
1.) Make a node and paste this into it. Make the path /formRelay
if(isset($_POST['email'])){
function is_valid_email($email) {
$result = TRUE;
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
$result = FALSE;
}
return $result;
}
function random_password($length = 10) {
// This variable contains the list of allowable characters for the
// password. Note that the number 0 and the letter 'O' have been
// removed to avoid confusion between the two. The same is true
// of 'I', 1, and l.
$allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
// Zero-based count of characters in the allowable list:
$len = strlen($allowable_characters) - 1;
// Declare the password as a blank string.
$pass = '';
// Loop the number of times specified by $length.
for ($i = 0; $i < $length; $i++) {
// Each iteration, pick a random character from the
// allowable string and append it to the password:
$pass .= $allowable_characters[mt_rand(0, $len)];
}
return $pass;
}
function validate_pass($pass,$pass2) {
if ($pass != $pass2) return t('Both passwords must match.');
if (!strlen($pass)) return t('You must enter a password.');
if (ereg(' ', $pass)) return t('The password cannot contain spaces.');
if (ereg("[^\x80-\xF7[:graph:]]", $pass)) return t('The password contains an illegal character.');
if (preg_match('/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP
'\x{AD}'. // Soft-hyphen
'\x{2000}-\x{200F}'. // Various space characters
'\x{2028}-\x{202F}'. // Bidirectional text overrides
'\x{205F}-\x{206F}'. // Various text hinting characters
'\x{FEFF}'. // Byte order mark
'\x{FF01}-\x{FF60}'. // Full-width latin
'\x{FFF9}-\x{FFFD}]/u', // Replacement characters
$pass)) {
return t('The password contains an illegal character.');
}
if (strlen($pass) > 30) return t('The password is too long: it must be less than 30 characters.');
$min_pass_length = variable_get('toboggan_min_pass_length', 0);
if ($min_pass_length && strlen($pass) < $min_pass_length) return t("The password is too short: it must at least $min_pass_length characters.");
return 1;
}
//email processing
$email = $_POST['email'];
unset($_POST['email']);
//see if email address is valid
if(is_valid_email($email)){
$query = "select uid from users where name='".$email."'";
$emailSearch = db_fetch_object(db_query($query));
//If the email address exists then set the UID, otherwise set 0
if(is_object($emailSearch)){
//$userID = user_load(array($emailSearch->uid));
$userID = $emailSearch;
}
else{
$userID = 0;
}
}
//The email address is not valid
else{
$errors['email'] = 'A valid email address was not entered';
}
//Password processing
if(isset($_POST['password1'])){
$valid_pass = validate_pass($_POST['password1'],$_POST['password2']);
if($valid_pass == 1){
$password = $_POST['password1'];
}
else{
$errors['password'] = $valid_pass;
}
}
else{
$password = random_password();
}
//determine emails to be sent
if(isset($_POST['emailToIX'])){
$emailToIX = $_POST['emailToIX'];
unset($_POST['emailToIX']);
}
if(isset($_POST['emailToUser'])){
$emailToUser = $_POST['emailToUser'];
unset($_POST['emailToUser']);
}
//return for errors
if(isset($_POST['returnNode'])){
$returnNode = $_POST['returnNode'];
unset($_POST['returnNode']);
}
//set roles
if(isset($_POST['roles'])){
$roles = $_POST['roles'];
unset($_POST['roles']);
}
unset($_POST['submit']);
//Check if required & add variables
foreach($_POST as $key => $value){
if(substr($key, 0,9) == "required-"){
if(!is_array($value) && $value == ""){
$errors['fields'][substr($key, 9)] = $key;
}
$data[substr($key, 9)] = $value;
}
else{
$data[$key] = $value;
}
}
if(isset($errors)){
//There are errors so don't create the account yet. Instead, return the user to the form and show error messages
$_SESSION['errorFields'] = $errors;
$_SESSION['fillFields'] = $data;
$_SESSION['fillFields']['email'] = $email;
drupal_goto($returnNode);
}
else{
//Create the new user!
if($userID == 0){
$data['pass'] = $password;
$data['name'] = $email;
$data['mail'] = $email;
//add roles
if(isset($_POST['roles'])){
$data['roles'] = $roles;
}
$data['status'] = isset($_POST['status']) ? $_POST['status'] : 1;
//create the account
$account = user_save($userID, $data);
//send user the mail
$variables = array('!username' => $email, '!site' => variable_get('site_name', 'Drupal'), '!password' => $password, '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $mail, '!date' => format_date(time()), '!login_uri' => url('user', NULL, NULL, TRUE), '!edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE), '!login_url' => user_pass_reset_url($account));
$from = variable_get('site_mail', ini_get('sendmail_from'));
$subject = _user_mail_text('welcome_subject', $variables);
$body = _user_mail_text('welcome_body', $variables);
drupal_mail('user-register-welcome', $email, $subject, $body, $from);
drupal_set_message(t('Further instructions have been sent to your e-mail address.'));
//If the user is not already logged in then log them in as the new account
global $user;
if($user->uid == 0){
user_authenticate($email, trim($password));
}
//drupal_goto();
}
//The user already exists so update the user's info!
else{
//add roles
if(isset($_POST['roles'])){
$data['roles'] = $userID->roles;
}
//update the account
$account = user_save($userID, $data);
//send the mail -- this time a link for them to change their password
$from = variable_get('site_mail', ini_get('sendmail_from'));
drupal_set_message(t('Your account has been updated and further instructions have been sent to your e-mail address.'));
$variables = array('!username' => $email, '!site' => variable_get('site_name', 'Drupal'), '!login_url' => user_pass_reset_url($account), '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $account->mail, '!date' => format_date(time()), '!login_uri' => url('user', NULL, NULL, TRUE), '!edit_uri' => url('user/'. $account->uid .'/edit', NULL, NULL, TRUE));
$subject = _user_mail_text('pass_subject', $variables);
$body = _user_mail_text('pass_body', $variables);
$mail_success = drupal_mail('user-pass', $email, $subject, $body, $from);
}
//send out all mail
if(isset($emailToIX)){
foreach($data as $key=>$value){
$mailMessage .= "$key: $value \n";
}
drupal_mail('New Website Registration', $emailToIX, 'New Website Registration', $mailMessage, 'user@drupal.org');
}
}
}
2.) Put this in a file on your server and call it formrly.inc:
ef(isset($_SESSION['fillFields'])){ foreach($_SESSION['fillFields'] as $key=>$value){ $fieldValues[$key] .= "value=\"$value\""; } } if(isset($_SESSION['errorFields']['fields'])){ foreach($_SESSION['errorFields']['fields'] as $key=>$value){ $fieldValues[$key] .= " class=\"form-text error\" "; } } //print_r($_SESSION['fillFields']); if(isset($_SESSION['errorFields'])){ echo '<div id="message"><div class="messages error"><ul>'; echo "<li>Required fields are unfilled</li>"; } if(isset($_SESSION['errorFields']['email'])){ $fieldValues['email'] .= " value=\"".$_SESSION['fillFields']['email']."\"class=\"form-text error\" "; echo "<li>".$_SESSION['errorFields']['email']."</li>"; } if(isset($_SESSION['errorFields']['password'])){ $fieldValues['password'] .= " class=\"form-text error\" "; echo "<li>".$_SESSION['errorFields']['password']."</li>"; } if(isset($_SESSION['errorFields'])){ echo '</ul></div></div>'; }
3.) Make profile fields for any forms you want to use and create the forms:
include("/usr/home/harry100/formrly.inc");
Personal Information
First:
echo $fieldValues['profile_first']; />
echo $fieldValues['profile_first']; />
Last:
echo $fieldValues['profile_last']; />
echo $fieldValues['profile_last']; />
Company:
echo $fieldValues['profile_company']; />
echo $fieldValues['profile_company']; />
Title:
echo $fieldValues['profile_title']; />
echo $fieldValues['profile_title']; />
echo $fieldValues['profile_mail']; /> Join our mailling list
Account information
Email: *
echo $fieldValues['email']; />
echo $fieldValues['email']; />
Your preferred username; punctuation is not allowed except for periods, hyphens, and underscores.
Password:
echo $fieldValues['password1']; />
echo $fieldValues['password1']; />
Enter password again:
echo $fieldValues['password2']; />
echo $fieldValues['password2']; />
Comments
Here's how the form should look
Ignore the form I tried to paste directly above. This is how it should look:
I'll keep an eye on this forum. Feel free to post questions/comments.
Hello Flamingan, I'm glad to
Hello Flamingan,
I'm glad to find some information about this problem. I need to have two different registration forms for two different roles on my website, do you think I could manage something with your code for this ?
I also use the roleacess module which ask the user what kinsd of account he wants before redirecting him to the registration form. Maybe I could couple the both, what do you think about that ?
Thank you very much for this code.
Matt
subscribe
subscribe
This should work for you.
This should work for you, bumathan. It's working well enough for my client.
It should be easy to setup the roles thing. Just use checkboxes like this:
<input type="hidden" name="roles[20]" value="20" />(where '20' is whatever role id you want the user assigned to)Good luck!
It will be nice if its a
It will be nice if its a drupal module, good job
Has anyone tried to make a
Has anyone tried to make a module from this piece of code?
Best regards,
John
Hi bumathan, do you succeed
Hi bumathan,
do you succeed ? I have the same needs...
Thx and thx flamingvan
R
Import in drupal
Hello, I have the same problem on my site.
I don't understand how to import your code in drupal??
Can you explain how?
Thanks,
i have done above steps but not working
i have created new content page with type content and try to make path /formRelay
but it is not allowed it can be without "/"
and copy the code to this page body "php code type"
i created a new file named formrly.inc in theme folder and copy the code to it
i created new content page and past the form html to it
but it not working
what is this file path
include("/usr/home/harry100/formrly.inc");
help plz
1) Make a node and paste this into it. Make the path /formRelay
can u plz explain more on how that can be done??
thnx
How to create a node in Drupal
If you'd like to know how to create a node in Drupal - spend some time and read help topics. It is really easy. Don't ask people to spend their precious time to explain you how to power your PC on etc. Don't forget this is a free forum.
Need real server security? Get in touch
problem on modify registration form
Hello any one can help me for how to modify registration form, i need add two field in top but in same field set and after username i add a button for check username is exist after that email field ,password, confirm password. how can i do this, plz. give me the solution if possible.
or send me on my email id rajenthakur.kumar@gmail.com
Membership types and registration modification
You can always use this module
http://drupal.org/project/nf_registration_mod
Are you using this module?
Are you using this module? I'm looking for some simple scenario documenation, I just don't get its README - http://drupal.org/node/299653
I'm wondering if anyone has
I'm wondering if anyone has gotten this to work, I fully understand steps 1 & 2, but the author didn't really explain the last step, I don't understand where you are supposed to put this code that he wrote, if you just put it into a node it doesn't work.
Any news on further
Any news on further developments with this? I am seeking a method for creating two separate registration forms for two user types... employer and jobseeker. Obviously the roles differ a lot so I do not want them to have the same registration form.
Is this script suitable for D6?
Query
Hi Everyone,
I have the same requirement. I have two roles. 1. Doctors 2. Staff
I need to have two different registration pages for both of them assigning them there respective roles.Can anybody help me how can I do that? How can I modify the create new user page i.e the default page for registration All I need a page having two links
Register as a doctor
Register as a staff member
The person registering from the doctor's page should be automatically assigned the role doctor. Same goes for staff
I hope that the picture is clear now.
Thanks
_
There are currently 2 options for d6. If you want to use the core profile module, you can use the contributed http://drupal.org/project/profile_role module. If you want profiles to be full fledged drupal nodes you can use the http://drupal.org/project/content_profile and http://drupal.org/project/autoassignrole modules (you need the dev versions of both modules and to use the 'path' method of role assignment).
More Details Required
I have some requirement here. I am a total novice for drupal and php, but have some experience on Asp.Net
I have a requirement here:
I have already told that there are two roles doctors and staff. When the user creates his/her account and applies for a role, the application is forwarded to the admin for approval. Here it's working fine.
Now what I need is that once the user logs in the first time or a number of times he must first be asked to fill in the detailed form i.e a doctors form for a doctor role applicant and a staff role for a staff role applicant. And then he will have the privileges of the role.
So how to create that form and how to redirect the user the very first time or any time while he has not submitted the form already, to the form's url?
Or is there any other good suggestion. I would prefer some step by step procedure to be summarized since I am a complete beginer.
Best Regards
_
In order to be more specific, I would need to know which route you're going to take-- the core profile module or the content_profile module.
Progressing..
Hi!
Ok I would take the content Profile module. Let me give you some more details and work flow so that you have a clear vision and better understanding.
The things is that. Once a staff logs in and creates his/her profile. Now I need a block that will display the links for the following
-Create new Patient's Profile
-View All Patients (Can also edit patient's profile)
-can leave comments (can do it not an issue fine!)
So it means that this "Staff" member can create a new "Patient Profile". Which would be a form containing basic patients information, images of patient, patient Xrays, Patient CT SCAN reports etc (Ofcourse some of the fields would not be mandatory like xray etc but should be insert-able if they are provided in future) assigned doctor (not mandatory).
Note that staff is a role and patient is NOT A ROLE. So staff will enter his information only first time which will not be editable by him unless approved by admin.
Now this is all with satff. With the doctor's role, First step is same for the doctor i.e providing his full info. Now once he has done this he can request the admin to give him/her more privileges or he can directly get the privileges of ONLY viewing his assigned patients or all patients for consultancy and can post his/her suggestions for the respective patient via COMMENTS which is not an issue.
Questions:
1. How are we going to make this Create New Patient form with these fields. Ok If we have only the defualt fields in the form and Images and video feeds for the pateints are stored separately then HOW ARE WE GOING TO LINK THEM TO THE PARTICULAR PATIENT? The weform module has limited fields. CCK? then how to use it?
2. How a doctor can view only those patients that are assigned to him/her?
I hope that he picture is clear now. Should you need any more info please ask.
If I just get a startup I'll be able to do it. My deadline is tough so please help me for some luck.
Thankyou for your concern and help
Best Regards
Some more
Well I first need the basic functionality, leave the vedio stuff for the time being but the basic registration and access stuff should work.
I also want to know (if it's possible) how can view all patients in list on a page instead of the default view of webform and when we click on that particular patient's link then the patient's profile can be viewable. Secondly it is worth noting that the staff can also ONLY view the list of the doctors available (no editing) since he has to assign one or more doctors to the patient. One way of doing that is to populate the select field with the available doctors name from the database, but the question arises how to do that?
I hope that the flow is making sense now. This project will help community all over the world to get doctors suggestions from all over the world for crucial disease patients so please take a little time and have your contribution too.
Many Thanks
Best regards
Multiple reg forms using content profile
WorldFallz
Using method 2, can you can you give me a few hints on setting up paths to "create new user" with the two different content_profile content types I've built?
Thanks, O knower of things arcane!
_
You would create 2 different content types for the different registration forms as desired. Then, autoassignrole, has the option to specify certain paths for different role registrations (ie example.com/user/role1)-- it will actually create a menu block with links for the different registrations. You might have to use the dev versions of content_profile and autoassignrole -- I'm not sure this feature has been committed to the official release yet. I believe it's also described in the documentation for both modules.