<p>The only model passed into the <code>guestEntries.beforeSave</code> event and returns from it is Craft's <a href="https://craftcms.com/classreference/models/EntryModel" rel="nofollow">EntryModel</a>, so even if you create your own <code>MyEntryModel</code> inside the event with it's own attributes and validation rules, there's not a clean way to return that model back to the controller to return to the template to display.</p>

<p>The easiest thing to do would be to fork the plugin and change <a href="https://github.com/pixelandtonic/GuestEntries/blob/master/guestentries/controllers/GuestEntriesController.php#L175" rel="nofollow">GuestEntriesController</a> so that's its using a custom <code>MyEntryModel</code> that extends Craft's <code>EntryModel</code> and adds it's additional attributes/validation rules as required.</p>

CC BY-SA 3.0
2016-06-22T21:11:31.480Z
2016-06-22T21:11:31.480Z
Brad Bell
<p>Say, I want to validate an email address or a special URL e.g. YouTube URL, would I be able to use a custom plugin with the <code>guestEntries.beforeSave</code> hook to do this?</p>

<p>The basic hook call:</p>

<pre><code>craft()-&gt;on( 'guestEntries.beforeSave', function(Event $event) {
    // Call custom validation here
});
</code></pre>

<p>Would I be able to setup a model with the method <code>defineAttributes</code> and run that?</p>

<guest-entries><plugin-guestentries>
Is it possible to use `guestEntries.beforeSave` to validate custom fields?
# Is it possible to use `guestEntries.beforeSave` to validate custom fields?

(Asked by: username_0 on 2016-06-21)

Say, I want to validate an email address or a special URL e.g. YouTube URL, would I be able to use a custom plugin with the guestEntries.beforeSave hook to do this?
The basic hook call:
craft()->on( 'guestEntries.beforeSave', function(Event $event) {
    // Call custom validation here
});

Would I be able to setup a model with the method defineAttributes and run that?

**Tags:** guest-entries, plugin-guestentries


---

## 1 answers

### Answer by username_1 on 2016-06-22. Score: 1

The only model passed into the `guestEntries.beforeSave` event and returns from it is Craft's [EntryModel](https://craftcms.com/classreference/models/EntryModel), so even if you create your own `MyEntryModel` inside the event with it's own attributes and validation rules, there's not a clean way to return that model back to the controller to return to the template to display.

The easiest thing to do would be to fork the plugin and change [GuestEntriesController](https://github.com/pixelandtonic/GuestEntries/blob/master/guestentries/controllers/GuestEntriesController.php#L175) so that's its using a custom `MyEntryModel` that extends Craft's `EntryModel` and adds it's additional attributes/validation rules as required.


---

