Checking if an attribute handle exists
Permalink
I've looked around the forum and C5 source for this and found a few answers, but nothing that has actually worked.
I have a single page in the dashboard to add pages, and in the controller I need to validate all of the attribute handles recieved.
I have tried using :
And just
But I get a different result if I send it a hard coded string like 'meta-title', which it will correctly say exists, but the moment I send it the exact same string that was retrieved from the sent data, it says the attribute handle doesn't exist. To be clear, the hard-coded value and the value retrieved from the form are both equal to 'meta-title'.
I have a single page in the dashboard to add pages, and in the controller I need to validate all of the attribute handles recieved.
I have tried using :
And just
$ak = CollectionAttributeKey::getByHandle('my_attribute_handle'); if (!is_object($ak))
But I get a different result if I send it a hard coded string like 'meta-title', which it will correctly say exists, but the moment I send it the exact same string that was retrieved from the sent data, it says the attribute handle doesn't exist. To be clear, the hard-coded value and the value retrieved from the form are both equal to 'meta-title'.
Still doesn't work actually, thought I had figured it out...
If you are going to give yourself a 'best answer', please add some value to your post to help others in the future.
I thought I had solved my problem, so I marked it as best answer. I realized later that I hadn't solved the problem, but I don't think that there's a way to just unmark a response as best answer other than marking another response as best answer.
I should have probably put the reason for the edit!
I should have probably put the reason for the edit!
Could you share your code, both from the view where attributes are entered and from the controller where validation takes place? It's a bit hard to know what the problem is with the description you give.
*EDIT:
The actual problem was that I had to do strval() on a string. Fun!
*Original
I finally found the solution. The problem was with the binary of the strings.
Instead of using what I hand found in another post (https://www.concrete5.org/community/forums/chat/check-if-attribute-handle-exist) I now use
Definitely not the most efficient solution, but makes sure that it is a binary-safe check.
The actual problem was that I had to do strval() on a string. Fun!
*Original
I finally found the solution. The problem was with the binary of the strings.
Instead of using what I hand found in another post (https://www.concrete5.org/community/forums/chat/check-if-attribute-handle-exist) I now use
Definitely not the most efficient solution, but makes sure that it is a binary-safe check.