Text replacement on field value before saving

A place for users and developers of the Xataface to discuss and receive support.

Postby 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/
cls
 
Posts: 15
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
cls
 
Posts: 15
Joined: Wed Dec 31, 1969 5:00 pm

Postby 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
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby cls » Fri Nov 17, 2006 5:11 am

I'm sorry for all my stupid questions :)

Thank you very much, Steve.
cls
 
Posts: 15
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Nov 17, 2006 12:07 pm

hehe.. no such thing as a stupid question :)

Glad to help.
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 27 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved