Moodle Registration Form Edit - moodle

I am using moodle 2.8.1
My query is regarding Moodle registration form:
I want to add a confirm password field which would be required same as Email(again) field.
And remove the Email(again) field.
And also it is not showing the phone no. fields in registration form while they are unlocked.

If you want to add fields to the registration form, you can do it using user profile fields in Site administration > Users > Accounts > User profile fields.
You have to set 'Display on signup page', which will show the field in the signup form, and 'Who is this field visible to' .
If you need more details refer: http://docs.moodle.org/26/en/User_profile_fields
Hope this helps.

We made a small open source module covering this use case.
It adds the field on the fly in the registration form, along with the necessary validation, using addRule and the compare rule.

In order to add confirm password field, you can custom login/signup_form.php file by adding one more field right after password field with compare rule like:
$mform->addElement('password', 'confirmPassword', get_string('password_confirm'), 'maxlength="32" size="12"');
$mform->setType('password', core_user::get_property_type('password'));
$mform->addRule('confirmPassword', get_string('missingpassword'), 'required', null, 'client');
$mform->addRule(array('confirmPassword', 'password'), get_string('passwords_must_match'), 'compare', 'eq', 'client');

Related

How to cross-validate contact form 7 form fields?

I want to make two sperate check box groupe. Lets say
Front end courses
-Bootstrap
-React Js
-Angular js
Back end courses
-C#
-Node
-PHP
on submitting form I want to make sure at least one course is selected by the user. Lets say a student selects ReactJs.
I have tried below code but it makes one option mandatory for all checkbox groups
[Checkbox* checkbox-11 ",Bootstrap" "React Js" "Angular JS"]
[Checkbox* checkbox-12 ",C#" "Node" "PHP"]
How can I make at least one option selected mandatory from any of the checkbox groups
field validation takes place post form submission. To solve this problem you need to make neither field mandatory, and then do a custom validation on the server side. CF7 plugin allows you to add custom validation to individual field but does not allow you to validate a field wrt to the value of other fields in the form.
To do this you need an extension such as the Smart Grid-layout plugin which has a validation hook that gives you access to the entire form's submitted data and therefore cross-validate your fields,
add_filter('cf7sg_validate_submission', 'cross_validate_submission',10,3);
function cross_validate_submission($validation, $submission, $form_key){
if(empty($submission['fe-courses']) && empty($submission['be-courses'])){
$validation['fe-courses']='You need to select at least 1 course!';
}
return $validation;
}

Acumatica / Myob Advanced: add an email field

On Myob Advanced (Acumatica), we would like to add a salespersons email address to the Salespersons page (AR205000). This is so that we can then add this field to the Sales Order email template, allowing us to CC the salesperson in every time their customer places an order.
Ive tried to implement this extra field, "Salespersons Email Address"; but I am having some issues.
It will only allow me to save 25 characters within the text box? How come I'm unable to add more than 25 characters?
Email fields that come with the software all have the code of px:PXMailEdit. However, i cant seem to be able to create a MailEdit field, only a px:PXTextEdit field? Why is this?
Thanks for your help. If this doesnt make sense or you need further info LMK.
Currently, Layout Editor does not support PXMailEdit control. Please find below the steps to add a custom email field on the Salespersons screen:
For the SalesPerson DAC, ceate a new field of the string type with length set to 255 (this is the length defined in the PXDBEmailAttribute used on all email fields in Acumatica/MYOB Advanced):
Replace generated attributes with the attributes below, save your changes and publish customization:
[PXDBEmail]
[PXUIField(DisplayName="Email Address")]
Open the Salespersons screen in Layout Editor and add TextEdit control for the custom field declared on step 1, then save your changes:
Select Edit Project Items from the File menu and change control type from PX.Web.UI.PXTextEdit to PX.Web.UI.PXMailEdit in the XML changeset generated for the Salespersons screen, save your changes and publish customization one more time:
This is how custom email field should look like on the Salespersons screen after you complete the steps above:
Using Salesperson's email in Automation Notifications:
If you set up custom Email Address field from the Salespersons screen as CC address in Sales Order notification:
the system will automatically include Email Address from the Default Salesperson in notification message:
Using Salesperson's email in Notification Templates:
This might seem a litle confusing, but the Sales Person node available for selection on the Notification Templates screen represents an Employee linked with a Salesperson (see screenshot below for details):
With SalesOrderNotification's CC field set to ((SalesPerson.SalesPersonID.UsrEmailAddress)), the system should automatically include Email Address from the Default Salesperson in the generated email:

Unique field in user registration form in Drupal 7

I am working in drupal 7. I need a field in the user registration form which needs to be unique. It is an integer field which stores the ID of the user. I have been searching around for a few hours now without any development. Can someone guide me through this?
Thank You.
You can add a custom "staff id" field to the user entity type from admin/config/people/account/fields (configuration->people->account settings). You can add a new integer field, and mark it to display in the registration form, and/or required.
To check that the field value is unqiue you will need to use a custom module. In your custom module use the form_id_form_alter hook to add a custom validation to the registration form. Then during validation you can check that the value does not already exist in the database and return a form error.
Example of the custom module:
<?php
function mymodule_form_user_register_form_alter(&$form, &$form_state, $form_id){
$form['#validate'][] = 'mymodule_user_registration_validate';
}
function mymodule_user_registration_validate(&$form,&$form_state){
$staff_id = $form_state['values']['staff_id_field'];
$check_unique_query = 'SELECT field_staff_id_value FROM {field_data_staff_id} WHERE field_staff_id_value = :staff_id LIMIT 1';
//if a result is returned, that means the $staff_id exists
if (db_query($check_unique_query,array(':staff_id'=>$staff_id))->fetchField()){
form_set_error('staff_id_field','This Staff ID is already in use');
}
}
Have you tried the Unique field module? Pretty sure it does what you need here.
Field validation does the trick https://drupal.org/project/field_validation. You can set any rules per field even on the registration form

Joomla Form Field User Front End

I am trying to use JFormFieldUser::getInput as an input to my Joomla forms.
In the backend (logged in with the super user), when I call this method, it produces a nice 'select user' box when clicked displays a list of all users to chose from.
I have been trying to use the User form field on a front end form (logged in with the super user). The result is some what confusing and undesirable. A 'select user' link is produced, but when clicking on it, the result is that the super users, 'User profile' is loaded up: not a list of all users.
Why is this, and how can i make 'select user' show the full list of users like it does in the backend.
Joomla 3 (from your field definitions):
<field name="field_name" type="sql" label="COM_FIELD_LABEL"
sql_select="id,name"
sql_from="#__users"
value_field="name"
key_field="id"
description=""
header="DROP_DOWN_HEADER"
required="false" />
Apparently it can't be done
The JForm (Joomla) User field is the Joomla core field that you can
see in Joomla article form to select a user (lightbox with list of
user). Becareful this field can not be used on front-end because
Joomla core don't manage it on front-end... Often we replace this
field on front end with a select dynamic field.
I didn't have much luck with this. Instead I created my own component and added in the content from com_users. Worked a treat.
Can be done fairly simply but with some significant limitations - depending on your use case.
User must be logged in to backend (even if you are trying to access the information frontend). If they are not logged in, it will prompt for log in and break out of the modal :(
User must have permissions for User Manager
Then duplicate the \libraries\cms\form\field\user.php to a fields location of your choice (in a modal subdirectory) and rename it to something like user2.php. Make the class name JFormFieldModal_Users2 and the $type='Modal_Users2'.
Don't forget to add the new path to your form .xml if required. The type will be "modal_users2".
Last step. In user2.php, change:
$link = 'index.php?option=com_users&view=users&layout=modal&tmpl=component&field=' . $this->id
. (isset($groups) ? ('&groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&excluded=' . base64_encode(json_encode($excluded))) : '');
to
$link = 'administrator/index.php?option=com_users&view=users&layout=modal&tmpl=component&field=' . $this->id
. (isset($groups) ? ('&groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&excluded=' . base64_encode(json_encode($excluded))) : '');
A bit hacky, but served my purposes.
Less hacky, but less glamorous solution here: The SQL formfield type

How to override default user profile fields in drupal 7 ising form API?

I'd like to know how to override/change the default fields in user profile such as: button Save, name, timezone etc.
I'd like to alter, delete('cause i don't need them) some of them.
To alter the user profile i use the hook: hook_form_alter using which i managed to add my own fieldds to user profile. But now i want to alter the default fields. How can i do it?
It is possible with the hook_form_alter, though it is better to use hook_form_FORM_ID_alter!
To be able to alter the form you need to know the structure of the arrays, the easiest way to get to know this is by installing the Devel module. Then you can view the structure by placing dpm($form); inside your alter function.
You can use this function on your custom module or in your theme (in template.php file).
Usually user profile form_id is user_profile_form. A simple example would be:
function mymodule_form_user_profile_form_alter(&$form,$form_state,$form_id){
$form['timezone']['#access'] = FALSE; //remove the "timezone" field from the form (default value is still saved)
$form['field_somefield']['#weight'] = -50; //move the field up
$form['actions']['submit']['#value'] = t('Add this content now'); //change the submit button text
}
For a good tutorial see the Lullabot tutorial here (is for drupal 6 but works the same way for d7!).
API: hook_form_FORM_ID_alter