function exif_custom_new_map_form_submit in EXIF Custom 7
Form submission callback for exif_custom_new_map_form().
File
- ./
exif_custom.add.inc, line 55 - Form for creating a new mapping.
Code
function exif_custom_new_map_form_submit($form, &$form_state) {
// Handle file uploading.
$validators = array(
'file_validate_is_image' => array(
'',
),
);
// Save file as temporary.
$file = file_save_upload('example_file', $validators);
$fields = exif_custom_get_exif_fields($file->uri);
// Add the mapping to the database.
db_query('INSERT INTO {exif_custom_maps}(name) VALUES (:name)', array(
':name' => $form_state['values']['name'],
));
// Retrieve the mid.
$mid = db_query('SELECT mid FROM {exif_custom_maps} WHERE name = :name', array(
':name' => $form_state['values']['name'],
))
->fetchField();
// Save each of the field mappings.
foreach ($fields as $key => $value) {
if (is_array($value)) {
$value_for_db = implode("; ", $value);
}
else {
$value_for_db = $value;
}
db_query("INSERT INTO {exif_custom_mapped_fields}\n (mid, exif_field, exif_example, img_field)\n VALUES (:mid, :exif_field, :exif_example, :img_field)", array(
':mid' => $mid,
':exif_field' => $key,
':exif_example' => $value_for_db,
':img_field' => 'none',
));
}
drupal_set_message('New EXIF mapping has been saved: ' . $form_state['values']['name'], 'status');
// Redirect to the edit page.
$form_state['redirect'] = 'admin/config/media/exif_custom/map/' . $mid;
}