How to use a just created ID in another field, upon save
The answer is probably obvious, but I'm running in around in circles here. I have an IMAGES table with and image_id (primary key) field and an image_filename field.
I would like to integrate the value that will be stored into the image_id field into the filename I will store in the image_filename field (ex: flower22 where 22 is the image_id) when I first CREATE the entry.
Can I use the image_id created in other fields during that first save? How?
Comments
$fields['file'] = array('type' => 'file', 'file_name' => 'test_{id}');
I'm hoping to have it tested and ready tomorrow.
I was indeed already renaming the file in an on_after_post hook. I also put together some logic in an on_after_save hook to update some fields with the ID created during the (first) save. Your placeholders would, I think, greatly simplify this process.
$fields['file'] = array(); $fields['file_upload'] = array('type' => 'file', 'file_name' => 'test_{id}');
Name a field name with a suffix of "_upload" will automatically transfer the name of the file to that field's value.
Yes, adding the '_upload' suffix does transfer the filename to that field's value. However, using the 'file_name' parameter does not change the transfered filename.
So even if I've set 'file_name' to 'test_{id}', and the name of the file being uploaded is "orange.txt", I'm still getting "orange.txt" transfered to the field and saved to the database.