Search

When creating a datasource filter, is it possible to check for empty fields?

I have a section that includes "sender" and "receiver" fields, but I want to create a datasource that only outputs items where the "sender" field has content but where "receiver" is empty.

I've tried leaving the "receiver" field empty in my filter, entering "null" and entering "regexp: ^$", but nothing works. Am I missing something?

It's fairly trivial to access the right elements in the XSLT, but for performance reasons it would seem to make sense to narrow the filter as much as possible to limit the XML output.

In a datasource filter you should be able to access the fields by using $_POST['fields']. But, even better, the delegate also provides the data. Take a look at line 274 ff. of event.section.php for example (this is the EventPostSaveFilter delegate). You will see that you can use $context['fields'] to get the data.

Michael, thanks for the quick reply!

I'm afraid that's a little over my head, though. I was hoping there was some syntax I could use within the GUI datasource editor to indicate that a field should be empty, a la this:

filter empty fields

But that's not possible, I take it?

Sorry, my bad! I thought about a (hand-made) event filter...

Unfortunately I have no idea at the moment regarding your real problem.

We need an "IS NULL" option for data source filtering.

Yes, indeed... But I am afraid that new filtering logic will have to wait until Symphony 3.

The latest version of the Select Box Link field should support this. You can use values sql: NULL and sql: NOT NULL. I don't think the Select Box Link field supports regular expression matches, only the above, numeric ID, and handle string matching.

Here's the code that achieves this, for reference: https://github.com/symphonycms/selectbox_link_field/blob/master/fields/field.selectbox_link.php#L405

Nick, how can you know all this? I'd like to know how your head works! :-)

But if we got an "IS NULL" option there would probably be endless other options needed. What would really be handy is an option to skip the built-in filtering and sorting options and just write the whole MySQL query. I know that can be done through a custom data source but with this option your DS could remain editable and you wouldn't have to muck around with the php. You would, of course, have to be proficient in writing queries.

Nick, you are teh bomb — thanks, that was exactly what I was looking for! Works like a charm.

Hmm, now I'm in a situation where I'd like to only display entries where a "Date" field is empty. The sql: NULL syntax is specific to the Select Box Link field, and there is no equivalent for other field types, is there?

If not, I definitely agree with wisolman that an "IS NULL" option would be very useful.

I know I can select the right entries in my XSLT easily, but I'm also populating a DS output paramter, which should only contain entries for which the date field is empty.

You can use the regexp or not-regexp filters that are available on all core fields. Remember this follows MySQL REGEXP, which may differ slightly from what you already know about REGEXP.

@bewildergeist: So you said sql: NULL worked for you? I'm trying exactly the same thing and it doesn't seem to work (and I double checked that I'm using the correct version of SBL). Any tips?

Never mind - sql: NULL does work. I messed up another area of my data source.

Sorry to bring back an old post, but what would that MySQL REGEXP look like that brendo refers to above?

I'm looking to filter only fields whose one text box is filled out. NOT NULL I guess.

Has anyone worked out how to filter and return only null text fields?

Did you get to the bottom of this?

Im curious too

Hi All. I'm trying to filter a datasource to return all entries where a text input is empty. Looking at the above, it seems that this isn't possible. Can this be true? It seems like such a simple thing to do.

I know this is an old thread, but I was wondering if in Symphony 2.3.x there is now a way to filter for NULL values?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details