Thanks for the detailed answer.
I have used method 1 and now have several calculated fields in my form.
I have added a script to show and hide the fields based on selecting a "Create New Contact" checkbox.
I can fill in the fields and save to the database using the process_request function.
I have also added a validation rule when there is an email address which points to the email validation rule in the contacts module. This works correctly, i.e. it allows the save when there are no duplicate emails and stops the save and displays a message when a duplicate email is found.
The last little problem I am trying to solve is that when a duplicate email is found it hides the calculated fields even though the "Create New Contact" checkbox is still selected. If I then uncheck the checkbox and recheck it the fields show up again, still filled out and with the duplicate email error message.
I would like the validation rule to return to the form with the calculated fields still showing.
I am using the following code.
Load_js and eval_js in the QFfield for the "Create New Contact" checkbox.
public static function QFfield_create_new_contact(&$form, $field, $label, $mode, $default, $desc, $rb_obj) {
if($mode=='add') {
load_js('modules/Trading/Quote/cchange.js');
eval_js('hideFields(0);');
$form->addElement('checkbox', $field, $label, null, array('onclick'=>'hideFields(this.checked);','id'=>$field));
} else {
}
}
and the cchange.js file to show or hid the fields. This was copied from the assets module.
function hideFields(index) {
hide_fields = 'none';
if(index != 0) {
hide_fields = '';
}
$('_last_name__data').parentNode.style.display=hide_fields;
$('_first_name__data').parentNode.style.display=hide_fields;
$('_group__data').parentNode.style.display=hide_fields;
$('_work_phone__data').parentNode.style.display=hide_fields;
$('_email__data').parentNode.style.display=hide_fields;
}
Thanks for all your help.
Jon