Page 1 of 1

PostPosted: Thu Nov 16, 2006 3:21 pm
by cls
Hi all,

I need to execute some text replacement (or PHP string functions) on a text field before it's saved.
I've a table with some fields, one of them is a file field for images upload(*).
I want to sanitize the value of that field file name, if the user uploads a file containing spaces and other weird characters.
So in the end the table will be updated with the sanitized value.

It is possible with a beforeSave function?

Thanks in advance,
Claudio

(*) http://framework.weblite.ca/forum/dataface-users/664341200/

PostPosted: Thu Nov 16, 2006 5:11 pm
by shannah
Ideally it would be nice to be able to do this with a beforeSave() trigger, but the way it currently is set up you can't. There are 2 options that I use consistently in this case.

1. Use an afterSave() trigger to perform the changes directly in SQL (after the record is already saved).

2. Use the %field%__pushValue() and %field%__pullValue() methods to massage data as it is received from the forms.
http://framework.weblite.ca/documentation/how-to/how-to-define-custom-serialization-for-fields

Hope this helps a little.

-Steve

PostPosted: Thu Nov 16, 2006 7:17 pm
by cls
> 1. Use an afterSave() trigger to perform the changes
> directly in SQL (after the record is already saved).

Sorry, I'm hopeless... can you make to me an example?
And can I update another table field using a value from another field?
E.g. updating a Nicename field with a value based on a Name field?

Thanks,
Claudio

PostPosted: Thu Nov 16, 2006 8:25 pm
by shannah
Code: Select all

function afterSave(&$record){

    $app =& Dataface_Application::getInstance();
    $res = mysql_query("update `foo` set `Nicename`='bar' where `id`='{$record->val('id')}'", $app->db());
}



Best regards

Steve

PostPosted: Fri Nov 17, 2006 5:11 am
by cls
I'm sorry for all my stupid questions :)

Thank you very much, Steve.

PostPosted: Fri Nov 17, 2006 12:07 pm
by shannah
hehe.. no such thing as a stupid question :)

Glad to help.