Jump to content

Recommended Posts

Posted

Hi guys, I'm currently trying to add events to a calendar where each event will have a date as a parent.

I'm trying to error check duplicate entries under the same date to avoid having the system error show.

So an event can share the same name and title if it has a different parent essentially.

But I can't seem to find a selector to test this.

In words: 

if parent's name is $input->post->date and name is $input->post->name

then set error to 1 

Could anyone point me in the right direction?

Thanks

Posted

Anyway, if you would decide to do that check, you could do it like this:

if ($pages->get("parent.name=$input->post->date, name=$input->post->name")->id) // set error to 1

edit: Ryan has some important additions to this on a post bellow

  • Like 3
Posted

Anyway, if you would decide to do that check, you could do it like this:

if ($pages->get("parent.name=$input->post->date, name=$input->post->name")->id) // set error to 1
 
 
Be careful not to pass values from $input directly into a selector. They would need to be filtered before going into the selector. 
// convert to unix timestamp then back to string, just to ensure it's valid (this is just one way)
$date = date('Y-m-d', strtotime($input->post->date)); 

// sanitize name to be a pageName
$name = $sanitizer->pageName($input->post->name); 

if($pages->get("parent.name=$date, name=$name, template=event")->id) { 
  /* set error to 1 */ 
}
  • Like 5
Posted

You're right Ryan. I knew that onjegolders knows this, and just wanted to give him the idea of how to do it. But we can't forget that more people can follow these advises...

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...