Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Custom profile form.
- */
- function module_profile_settings_form($form, &$form_state, $profile) {
- $form = array(
- '#validate' => array('module_profile_form_validate'),
- '#submit' => array('module_profile_form_submit'),
- );
- $settings_form_fields = array(
- 'field_profile_other_location',
- 'field_profile_other_notification',
- 'field_profile_other_cv',
- 'field_profile_other_vat',
- );
- module_profile_add_custom_fields($settings_form_fields, $profile, &$form, &$form_state);
- $form['#profile2'] = $profile;
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- '#weight' => '1001',
- );
- return $form;
- }
- /**
- * Add fields from $form_fields to custom form.
- */
- function module_profile_add_custom_fields($form_fields, $profile, &$form, &$form_state) {
- $weight = 1;
- foreach ($form_fields as $field_name) {
- field_attach_form('profile2', $profile, $form, $form_state, NULL, array('field_name' => $field_name));
- }
- }
- /**
- * Custom validate callback to validate profile form fields.
- */
- function module_profile_form_validate($form, &$form_state) {
- // Here uploaded file is already validated and added to file_managed table but with status=0
- field_attach_form_validate('profile2', $form['#profile2'], $form, $form_state);
- }
- /**
- * Custom submit for profile partly forms.
- */
- function module_profile_form_submit($form, &$form_state) {
- // This line will put valid fid inside file field inside $form['#profile']
- field_attach_submit('profile2', $form['#profile2'], $form, $form_state);
- // After entity_save() field_data table will get fid, file_managed will change status value to 1
- profile2_save($form['#profile2']);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement