Welcome Guest, Not a member yet? Register   Sign In
Honeypot causing error
#1

(This post was last modified: 03-03-2025, 01:34 PM by frocco.)

Hello,

I enabled honeypot in config and now get this error when saving a record

Code:
if (!$record->hasChanged()) {

            return redirect()->back()
                ->with('warning', lang('App.messages.no_change'))
                ->withInput();
        }

        $record->page_url = url_title($record->page_title, '-');

        if ($this->page->protect(false)
            ->save($record)
        )

Unknown column 'honeypot' in 'field list'

I had to add unset to resolve this.

Code:
$post = $this->request->getPost();
        unset($post['honeypot']);
        $slider->fill($post);
Reply
#2

This field will be automatically filtered out if you do not disable field protection.
Reply
#3

(03-03-2025, 11:37 PM)michalsn Wrote: This field will be automatically filtered out if you do not disable field protection.

Thank you, I tried that and now I get an error.

There is no data to update.
Code:
$post = $this->request->getPost();
        //unset($post['honeypot']);
        $slider->fill($post);

        if (!$slider->hasChanged()) {

            return redirect()->back()
                ->with('warning', lang('App.messages.no_change'))
                ->withInput();
        }

        if ($this->model->protect(true)
            ->save($slider)
        )
Reply
#4

In your model set $updateOnlyChanged to false.

https://codeigniter.com/user_guide/model...nlychanged
Reply
#5

(03-04-2025, 07:39 AM)michalsn Wrote: In your model set $updateOnlyChanged to false.

https://codeigniter.com/user_guide/model...nlychanged

Thank you
Reply
#6

This happens because the honeypot field is included in the POST data, but your database table doesn’t actually have a column named honeypot. When you call $model->save() or $model->fill(), CodeIgniter tries to map all fields from the POST array to your database columns—leading to the Unknown column 'honeypot' in 'field list' error.

Why unset($post['honeypot']) fixes it
By unsetting the honeypot index from the POST array, you’re removing that field from the data you pass into $model->fill($data). As a result, CodeIgniter no longer tries to save the honeypot field to the database.

Alternative Approaches
Use $allowedFields in your Model

In CodeIgniter 4, if you set $protectFields = true; and specify only the valid column names in $allowedFields, any extra fields (like honeypot) will be ignored automatically.

php
Копировать
class PageModel extends Model
{
protected $table = 'pages';
protected $primaryKey = 'id';
protected $allowedFields = ['page_title', 'page_url', /* etc */];
protected $protectFields = true;
// ...
}
Then, calling $model->save($data) or $model->fill($data)->save() will skip any fields not listed in $allowedFields, so honeypot will not be inserted.

Manually remove/ignore honeypot

As you’ve already done, you can unset($post['honeypot']); before filling. This is perfectly fine if you only have a couple of forms that send a honeypot field.

Another option is to conditionally remove honeypot from the data in a global filter, or in your controller logic, before you ever call $model->save().

Custom Validation/Logic

If you want to detect the honeypot field being filled (e.g., to block bots), you could add extra logic in your controller or model. But typically, the built-in honeypot setting just needs you to avoid saving that field to the database.

Summary
The error arises because CodeIgniter’s model tries to persist a field (honeypot) that your table doesn’t have.

You can remove that field from the data (manually via unset()) or ignore it automatically by setting $allowedFields and $protectFields = true; in the corresponding model.

Either way, as long as the honeypot field is never mapped onto a real table column, the error will be resolved.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB