Created
September 16, 2013 15:29
-
-
Save mrded/6582200 to your computer and use it in GitHub Desktop.
File attachment VIA Form API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wj_profile_photo_upload_form() { | |
$form = array(); | |
$instance = field_info_instance('profile2', 'field_photo', 'profile'); | |
$field = field_info_field('field_photo'); | |
$form['profile_field_photo'] = array( | |
'#type' => 'managed_file', | |
'#upload_location' => file_field_widget_uri($field, $instance), | |
'#upload_validators' => file_field_widget_upload_validators($field, $instance), | |
'#value_callback' => 'file_field_widget_value', | |
); | |
$form['submit'] = array( | |
'#type' => 'submit', | |
'#value' => t('Upload'), | |
'#id' => 'wj-profile-photo-upload', | |
); | |
$form['#attributes']['enctype'] = "multipart/form-data"; | |
return $form; | |
} | |
function wj_profile_photo_upload_form_submit($form, &$form_state) { | |
if ($fid = $form_state['values']['profile_field_photo']) { | |
db_update('file_managed')->fields(array('status' => 1))->condition('fid', $fid)->execute(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment