custom attributes
Permalink
I'm working on a site that has a large user database. I'm trying to get the some of the fields to format correctly but am having no luck.. I know Andrew has a tutorial on it in 5.6, is there any for 5.7?
Thanks
Bob
Thanks
Bob
Is there a specific attribute type you are having problems with? Most of the 5.6 docs should be really close to what you need for 5.7
Hi Hutman,
I'm using the text attribute to format a phone number.. Here is what I got.. I can't get in to work.. Can you help me out??
Thanks
Bob
I'm using the text attribute to format a phone number.. Here is what I got.. I can't get in to work.. Can you help me out??
Thanks
Bob
<?php namespace Concrete\Attribute\Text; use Loader; use \Concrete\Core\Foundation\Object; use \Concrete\Core\Attribute\DefaultController; class Controller extends DefaultController { function saveForm($data) { //validate method ..then return null or true $e = $this->validateForm($data ['value']); //if there is no error, save it. if(!$e){ $this->saveValue($data['value'] ); } } public function validateForm($value) {
Viewing 15 lines of 27 lines. View entire code block.
I guess I'm not exactly sure what you're trying to do here. I can see that you are trying to validate the phone number is a certain format, but you are returning true only if there is an error, otherwise you are returning nothing (which will be false) and then only saving the attribute if the return is true, which it will only be if the phone number is wrong.
Hi Hutman
What I am trying to do is make sure the data [value] is in the correct format (xxx-xxx-xxxx). if it is then display it, if not erase the data and display the error message..
Thanks
Bob
What I am trying to do is make sure the data [value] is in the correct format (xxx-xxx-xxxx). if it is then display it, if not erase the data and display the error message..
Thanks
Bob
Well, I got it to save. However I do not see any way you can return an error for an attribute so I don't think that part is going to work. I would suggest adding some kind of mask to the field so that they can't enter something wrong. Here is how I changed it so that it will at least install/save if the attribute is entered in the correct format.
Notice I moved it to /application/attributes/phone/controller.php
<?php namespace Application\Attribute\Phone; use Loader; use \Concrete\Core\Foundation\Object; use \Concrete\Core\Attribute\DefaultController; class Controller extends DefaultController { protected $searchIndexFieldDefinition = array('type' => 'phone', 'options' => array('length' => 12, 'default' => null, 'notnull' => false)); public function form() { if (is_object($this->attributeValue)) { $value = Loader::helper('text')->entities($this->getAttributeValue()->getValue()); } print Loader::helper('form')->text($this->field('value'), $value); } public function composer() { if (is_object($this->attributeValue)) {
Viewing 15 lines of 40 lines. View entire code block.
Notice I moved it to /application/attributes/phone/controller.php
Hi Hutman
I put the file in /application/attributes/phone/controller.. But I keep getting
Class \Concrete\Attribute\Phone\Controller does not exist .. I'm lost.. any Ideas??
Thanks
Bob
I put the file in /application/attributes/phone/controller.. But I keep getting
Class \Concrete\Attribute\Phone\Controller does not exist .. I'm lost.. any Ideas??
Thanks
Bob
Forgot something.. After putting the the folder in /application/attributes , went to system & settings -> attributes -> types.. Got the error there..
Bob
Bob
This information should be in a file called controller.php which lives in the /application/attributes/phone directory