Wednesday, June 25, 2008

Empty & old Cake

Hi, pals!

I have one old project with cake 1.1. And, suddenly, I start to get a lot of "empty" message.

So, it's look like this:

site.com/ads/add

Model have (all field) -> VALID_NOT_EMPTY

In controller, before $this->Ad->save() I made this:

trim(...)
strip_tags(...)
And, even, I wrote:

if ($this->data['Field'] == '') die;

But... But after one-two day I can found in DB records with empty fields. ;(

Of couse, I trying to add record with empty fields an cann't do it. Cake work fine, and return me to /ads/add with error "Field cannot be empty"

But fields empty. I don't know, how spammers do it, but he do it fine ;-(

After week of a lot attempts to fight with this I start use function afterSave ;-)

So

afterSave

$id = $this->Model->GetId();
$data = $this->Model->read(null,$id);
if ($data['Field'] == '') -> $this->Model->del($id)

After this I got only useful record in database.

But, of couse, this decision is not so beauty ;-(

If you know HOW this spammers do it - I'll be very happy if you tell me

(Yes, I look apache logs and don't found anything strange)

Labels: , ,

2 Comments:

Blogger SzajbuS said...

Hi,
I was getting into this problem myself. It's not spam-related thing. My co-worker found out that it can be caused by the following example situation:

1. Article belongs to Category.
2. Article is created, but with no category specified.
3. Cake creates an empty category, and makes the created article belong to it.

I didn't try to replicate the problem, so you need to try this yourself.

4:41 PM  
Blogger Владислав said...

Thanks! But in this case model haven't any relation ;-(
I think I have "float bug" in my code, or bug in current beta-version of Cake 1.1.idontrememberdigit ;-)

So, with afterSave patch it's work fine. ;-)

1:03 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home