Text replacement on field value before saving

Archived from the Xataface Users forum.

cls — Thu Nov 16, 2006 3:21 pm

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/


shannah — Thu Nov 16, 2006 5:11 pm

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


cls — Thu Nov 16, 2006 7:17 pm

  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


shannah — Thu Nov 16, 2006 8:25 pm

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


cls — Fri Nov 17, 2006 5:11 am

I’m sorry for all my stupid questions

Thank you very much, Steve.


shannah — Fri Nov 17, 2006 12:07 pm

hehe.. no such thing as a stupid question

Glad to help.