Announcement

Collapse
No announcement yet.

Creating Email type field

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating Email type field

    Hi All, I hope to get some help here from veterans of ESPO CRM. I am newest to ESPO and just trying to get my head around it. I have created an entity (of the type base plus) and trying to have an email type field in this entity. I have gone through the documentation and looks like ESPO says email type field CANNOT be created directly, am wondering if anyone could point me to how it can he created indirectly. Anything will be much appreciated. Thanks.

  • #2
    Welcome to the forum etc, etc.

    Yes that right, there is still no "hold my hand" guide to make this type of field yet. The closest I can find is this thread here: https://forum.espocrm.com/forum/deve...mail-and-phone

    Indirectly method would just be create an entity, maybe something like "EmailCustom", then link two entity together by using Entity relationship. Not ideal but it would work (See: https://docs.espocrm.com/administrat...#relationships )

    Second method is to do similar above and use a paid for extensions which would allow you to do the above but link it in a more pleasing to the eyes way. (From Elba Soft)

    ---
    With that said, here is my advertisement: https://github.com/o-data/EspoCRM-Le...nd-Design/wiki
    Last edited by espcrm; 10-07-2021, 07:58 AM.

    Comment


    • #3
      Hi, you can do this easily via backend - whenever desired field will not be in email format (and not empty of course), EspoCRM will throw error to the user:

      PHP Code:
      private function validateEmailField(Entity $entity): void
      {
      $emailField $entity->get('title');

      if(!
      filter_var($emailFieldFILTER_VALIDATE_EMAIL) && $emailField != null)
      {
      throw new 
      Error('The input provided in field in not valid email.');
      }


      I tested it on Title field on Lead. This is not of course suitable if you want to be able to specify Email type field when you create a new field. This code is only for Lead entity entity as an example.

      Comment


      • espcrm
        espcrm commented
        Editing a comment
        Thank you for sharing the solution alter. But from reading the code with my layman mine, it seem that code is just to disable the Validation isn't it?

        How would you create a new 'email' field where you can use the + button for each CustomEntity for example?
    Working...
    X