Changing the signup.php page question

Changing the signup.php page question

by michael mike -
Number of replies: 8

Hello we have just installed Moodle at Yale University.  Todate we have the standard signup username, pword, email addresss, first name, surname etc.

I would like to get rid of a coupl of these fields I understand the concept of taking them away and putting in defaults for required fields however how about adding a new field.  What will this take.  My guess is that I can create my own table and key it off the users table. 

Anybody done this?

Average of ratings: -
In reply to michael mike

Re: Changing the signup.php page question

by Rob Hindman -
I just did this same thing on a site I'm working on.  In our case, to get it done a little more quickly, I just added fields to the end of the mdl_user table.  This way I didn't have to add any new db queries, since Moodle already pulls all fields from that table into an array. 

Code modification was then just a matter of copying and pasting other fields' code snippets and replacing the field names with the names of the new fields I added.  The files involved are login/signup_form.html (the HTML user interface) and login/signup.php (the PHP validation/error checking).

Additionally I added strings in the language file lang/en/moodle.php for the form labels I had to add for my additional fields.

BTW, if it would be useful for Moodle developers to know, the fields that I needed to add (because Moodle doesn't include them) were:
  • address2 (second line for a mailing address)
  • stateprov (state or province, since Moodle only asks for city)
  • zip (zip or postal code, since Moodle only asks for city)
Average of ratings: Useful (4)
In reply to Rob Hindman

Re: Changing the signup.php page question

by Uther Helios -
"Code modification was then just a matter of copying and pasting other fields' code snippets and replacing the field names with the names of the new fields I added. The files involved are login/signup_form.html (the HTML user interface) and login/signup.php (the PHP validation/error checking).

Additionally I added strings in the language file lang/en/moodle.php for the form labels I had to add for my additional fields."

Can you please send me the modified files to cosmin.artimof@oammr-galati.ro. I am really interested in seeing how exactly you have modified them. I am about to do the same thing to my files.
In reply to Rob Hindman

Odp: Re: Changing the signup.php page question

by Rafal Buz -
"I just did this same thing on a site I'm working on. In our case, to get it done a little more quickly, I just added fields to the end of the mdl_user table. This way I didn't have to add any new db queries, since Moodle already pulls all fields from that table into an array.

Code modification was then just a matter of copying and pasting other fields' code snippets and replacing the field names with the names of the new fields I added. The files involved are login/signup_form.html (the HTML user interface) and login/signup.php (the PHP validation/error checking).

Additionally I added strings in the language file lang/en/moodle.php for the form labels I had to add for my additional fields. "

Those bold ones are what I was looking for ^^ thank You m8 for post, was very usefull.

That would be nice if Signup form could be modifed from administrators panel.
In reply to Rafal Buz

Re: Odp: Re: Changing the signup.php page question

by Rambabu Dola -
Hi Rafal,

I need to add one filed in user profile page (For example: check box(input type) and I agree to the Terms and conditions(lable). Upto here i got the solution, but my requirement is

Terms and conditions must be anchor link(like this :I agree to the Terms and conditions ). Could you pls tell me how to do this one.

Thanks
Rambabu
In reply to Rambabu Dola

Re: Odp: Re: Changing the signup.php page question

by luchito alva -

Saludos.

Si me puede hacer el favor de decirme como modificó el archivo y la base de datos para poder añadir los términos y condiciones y añadir campos chek box..

Le estaré muy agradecido.

Si de algo le sirve esto para su problema revíselo USUARIOS/CUENTAS/Campos de perfil del usuario.

Lo que ocurre es que aquí no deja añadir campos de usuario(TIPO AREA DE TEXTO, no modificablle por el usuario) en los cuales se puedan añadir TERMINOS Y CONDICIONES(Para añadir T&C Moodle cuenta con la opción de redireccionar primero a la página de T&C colocando esa URL --VEA ESTO---  SEGURIDAD/POLITICAS DEL SITIO/ opción URL a la política del sitio).

El problema que yo tengo es que Necesito que un campo que ya añadi de MENÚ DESPLEGABLE en el formulario de registro (SIGNUNP) no me aparezca en el formulario de registro(EDITADVANCED). Este formulario de registro del Archivo php EDITADVANCED aparece cuando un usuario va a crear a otro habiendo entrado primero con los datos de usuario. En cambio el formulario de registro de SIGNUP aparece antes de que el usuario entre al sitio.

In reply to Rob Hindman

Re: Changing the signup.php page question

by Arabinda P -

Hi,

Thanks for a great post.

Could you please share the signup.php, signup-form.html files with me?

Please send them to my mail id - parabinda@gmail.com

Thanks

Arabinda

In reply to Rob Hindman

Re: Changing the signup.php page question

by Mudassar Mujawer -

Hi,

I have added my own dropdown in moodle signup form. But I didn't validate that. So pls help me how can i validate the my dropdown.

 

Here my code :

"$mform->addElement('select', 'hear_about_us', 'Where did you hear about us?', $hear_about_us,'Xonchange="showAboutUs(this.value)"');

$mform->addRule('hear_about_us', 'Where did you hear about us?', 'required', null, 'server');"

 

Let me know how can i validate this element.

You can also reply me on my email address "mmujawer@gmail.com".

In reply to michael mike

Re: Changing the signup.php page question

by Valentin Ioan Tincas -
Hello everyone! Thank you Rob ! I followed your guidelines about changing signup.php and I was successful. I make a difference if the user is an "alien" or not. If user is not an alien "username" and "password" fields are displayed only. If user chooses "yes" from "Are you an alien" drop down menu then two more fields are displayed in the form like this:
if($alien == 2)//if "ALIEN" is selected
{ $mform->addElement('text', 'space_ship_id', 'Space Ship ID', 'maxlength="100" size="25"');
$mform->addElement('landing_date', 'landing_date', 'Landing Date');
}
I used also a javascript autoSubmit() function on the <select name="alien" onChange="autoSubmit();"> element.
I added extra fields at the end of the mdl_user table for space_ship_id and landing_date.
The values for username and password are inserted into the table but the values for space_ship_id and landing_date are not inserted into the table. If I move space_ship_id and landing_date outside the if($alien == 2) block statement their values are inserted into the table.

Would you please help me to keep the dynamic way of displaying the two fields dependent on drop down menu and insert their values into the mdl_user table ?

here is my signup.php code
------------------------------------------------------------------------------------------------------------------
<script language="JavaScript">

function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}

</script>

<?php // $Id: signup_form.php,v 1.35.2.6 2008/07/23 05:21:21 nicolasconnault Exp $

require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');


class login_signup_form extends moodleform {
function definition() {
global $USER, $CFG;
global $creature;

 
 
$mform =& $this->_form;
 
 
if(isset($_GET["alien"]) && is_numeric($_GET["alien"]))
{
$alien = $_GET["alien"];
}
 
 
$mform->addElement('header', '', get_string('createuserandpass'), '');

 
$mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
$mform->setType('username', PARAM_NOTAGS);
$mform->addRule('username', get_string('missingusername'), 'required', null, 'server');
 
 
$mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
$mform->setType('password', PARAM_RAW);
$mform->addRule('password', get_string('missingpassword'), 'required', null, 'server');

$mform->addElement('header', '', get_string('supplyinfo'),'');

 
$mform->addElement('text', 'name', 'Name', 'maxlength="100" size="25"');
$mform->setType('name', PARAM_NOTAGS);
$mform->addRule('name', 'Missing name', 'required', null, 'server');
 
$mform->addElement('text', 'surname', 'Surname', 'maxlength="100" size="25"');
$mform->setType('surname', PARAM_NOTAGS);
$mform->addRule('surname', 'Missing surname', 'required', null, 'server');
 
if($alien == 2)//if "ALIEN" is selected
{
 
$mform->addElement('text', 'space_ship_id', 'Space Ship ID', 'maxlength="100" size="25"');
$mform->setType('space_ship_id', PARAM_NOTAGS);
$mform->addRule('space_ship_id', 'Space Ship ID', 'required', null, 'server');
 
$mform->addElement('landing_date', 'landing_date', 'Landing Date');
$mform->setType('landing_date', PARAM_NOTAGS);
$mform->setDefault('landing_date', '');
 
 
 
}
 
?>
 
<table cellpadding="9" cellspacing="0">

<form name="theForm" method="get">
 
<tr valign="top">
<td align="right"><b>Are you an Alien</b></td>
<td>
<select name="alien" onChange="autoSubmit();">
<option value="null"></option>
 <option value="1">YES</option>
<option value="2">NO</option>
 
 
</select>
</td>
 
</form>
</tr>
</table>
<?php
 

 
 
$nameordercheck = new object();
$nameordercheck->firstname = 'a';
$nameordercheck->lastname = 'b';
 
 
 
 
$country = get_list_of_countries();
$default_country[''] = get_string('selectacountry');
$country = array_merge($default_country, $country);
 
 
if( !empty($CFG->country) ){
$mform->setDefault('country', $CFG->country);
}else{
$mform->setDefault('country', '');
}
 
 
 
if (signup_captcha_enabled()) {
$mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps));
$mform->setHelpButton('recaptcha_element', array('recaptcha', get_string('recaptcha', 'auth')));
}

profile_signup_fields($mform);

if (!empty($CFG->sitepolicy)) {
$mform->addElement('header', '', get_string('policyagreement'), '');
$mform->addElement('static', 'policylink', '', '<a href="'.$CFG->sitepolicy.'" onclick="this.target=\'_blank\'">'.get_String('policyagreementclick').'</a>');
$mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
$mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'server');
}

 
 
// buttons
$this->add_action_buttons(true, get_string('createaccount'));

}

function definition_after_data(){
$mform =& $this->_form;

$mform->applyFilter('username', 'moodle_strtolower');
$mform->applyFilter('username', 'trim');
}

function validation($data, $files) {
global $CFG;
$errors = parent::validation($data, $files);

$authplugin = get_auth_plugin($CFG->registerauth);

if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
$errors['username'] = get_string('usernameexists');
} else {
if (empty($CFG->extendedusernamechars)) {
$string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']);
if (strcmp($data['username'], $string)) {
$errors['username'] = get_string('alphanumerical');
}
}
}

//check if user exists in external db
//TODO: maybe we should check all enabled plugins instead
if ($authplugin->user_exists($data['username'])) {
$errors['username'] = get_string('usernameexists');
}


if (! validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');

} else if (record_exists('user', 'email', $data['email'])) {
$errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
}
if (empty($data['email2'])) {
//$errors['email2'] = get_string('missingemail');//TVI 09/05/2010

} else if ($data['email2'] != $data['email']) {
$errors['email2'] = get_string('invalidemail');
}
if (!isset($errors['email'])) {
if ($err = email_is_not_allowed($data['email'])) {
$errors['email'] = $err;
}

}

$errmsg = '';
if (!check_password_policy($data['password'], $errmsg)) {
$errors['password'] = $errmsg;
}

if (signup_captcha_enabled()) {
$recaptcha_element = $this->_form->getElement('recaptcha_element');
if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
$challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
$response_field = $this->_form->_submitValues['recaptcha_response_field'];
if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
$errors['recaptcha'] = $result;
}
} else {
$errors['recaptcha'] = get_string('missingrecaptchachallengefield');
}
}

return $errors;


}
}

?>