# Validating 2 fields

**URL:** <https://discourse.getcockpit.com/t/validating-2-fields/2043>\
**Category:** Support\
**Created:** [August 14, 2021, 10:17pm UTC](https://discourse.getcockpit.com/t/validating-2-fields/2043 "2021-08-14T22:17:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcamachott](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/jcamachott/32/879_2.png) [@jcamachott](https://discourse.getcockpit.com/u/jcamachott)\
**Post date:** [August 14, 2021, 10:17pm UTC](https://discourse.getcockpit.com/t/validating-2-fields/2043/1 "2021-08-14T22:17:04Z")

</div>

Hi folks,

I have two fields setup in a collection

![image](https://canada1.discourse-cdn.com/flex030/uploads/getcockpit/original/1X/8a5960fa0828751f4760725804b738f6f6e0590f.png)

How can I validate the second date (Unpublish) to be after the first date (Publish)?

Thanks.

---

<div class="post-metadata">

**Author:** ![abernh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/abernh/32/859_2.png) [@abernh](https://discourse.getcockpit.com/u/abernh)\
**Post date:** [August 19, 2021, 8:43pm UTC](https://discourse.getcockpit.com/t/validating-2-fields/2043/2 "2021-08-19T20:43:38Z")

</div>

You could have a script listen for this trigger

```auto
# /modules/Collections/bootstrap.php:401
$this->app->trigger('collections.save.before', [$name, &$entry, $isUpdate]);

```

It will allow you to update the data for the to-be-saved `$entry`.  
This means you could enforce at that point that `unpublish_date` must be \>= `publish_date`.

You could put this script into `/config/bootstrap.php`

An alternative would be to use the `WRITE` rule for this particular collection.  
It allows you to access the following object via the variable `$context`:

```auto
            [
                'options' => $options,
                'entry' => $entry
            ]

```

As you can see it also contains the to-be-written `$entry` data, that again, can be adjusted.
