Advertisement
Guest User

Untitled

a guest
Nov 21st, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /**
  2. * Custom profile form.
  3. */
  4. function module_profile_settings_form($form, &$form_state, $profile) {
  5. $form = array(
  6. '#validate' => array('module_profile_form_validate'),
  7. '#submit' => array('module_profile_form_submit'),
  8. );
  9.  
  10. $settings_form_fields = array(
  11. 'field_profile_other_location',
  12. 'field_profile_other_notification',
  13. 'field_profile_other_cv',
  14. 'field_profile_other_vat',
  15. );
  16.  
  17. module_profile_add_custom_fields($settings_form_fields, $profile, &$form, &$form_state);
  18.  
  19. $form['#profile2'] = $profile;
  20.  
  21. $form['submit'] = array(
  22. '#type' => 'submit',
  23. '#value' => t('Submit'),
  24. '#weight' => '1001',
  25. );
  26.  
  27. return $form;
  28. }
  29.  
  30. /**
  31. * Add fields from $form_fields to custom form.
  32. */
  33. function module_profile_add_custom_fields($form_fields, $profile, &$form, &$form_state) {
  34. $weight = 1;
  35. foreach ($form_fields as $field_name) {
  36. field_attach_form('profile2', $profile, $form, $form_state, NULL, array('field_name' => $field_name));
  37. }
  38. }
  39. /**
  40. * Custom validate callback to validate profile form fields.
  41. */
  42. function module_profile_form_validate($form, &$form_state) {
  43. // Here uploaded file is already validated and added to file_managed table but with status=0
  44. field_attach_form_validate('profile2', $form['#profile2'], $form, $form_state);
  45. }
  46.  
  47. /**
  48. * Custom submit for profile partly forms.
  49. */
  50. function module_profile_form_submit($form, &$form_state) {
  51. // This line will put valid fid inside file field inside $form['#profile']
  52. field_attach_submit('profile2', $form['#profile2'], $form, $form_state);
  53. // After entity_save() field_data table will get fid, file_managed will change status value to 1
  54. profile2_save($form['#profile2']);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement