Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Memberprofiles - Check email field only accept valid email


Go to End
Reply

11 Posts   2113 Views

Avatar
Josua

1 March 2012 at 9:13am (Last edited: 1 March 2012 9:39am), Community Member, 86 Posts

Hi!

I'm trying to use the memberprofiles module, but I have a doubt:
Do you know how to make the email field only accept valid email address?

I mean a valid email format, not the validation through the use of sending an email.
Ie
martin -- incorrect email
martin@ -- incorrect email
martin@hotmail -- incorrect email
martin@hotmail.com -- correct email

Thanks,
Regards,
Jose

Avatar
Josua

7 March 2012 at 6:38am Community Member, 86 Posts

Hi all!

Does anyone know how to do this? :(

Thanks,
Regards,
Jose

Avatar
novaweb

7 March 2012 at 12:18pm Community Member, 115 Posts

Hola Jose,

(I haven't looked in to member profiles, but)

In the registration form, use the following form field type:

new EmailField("Email")

This will parse the email supplied and check it is valid.

Avatar
Josua

7 March 2012 at 8:44pm Community Member, 86 Posts

Hello Josh!

Ok, but I would have liked to do it without having to modify the code directly from the module.

Do you know if there is another way to do this?

Regards,
Jose

Avatar
ajshort

7 March 2012 at 9:23pm Community Member, 244 Posts

The form fields are generated by Member::getMemberFormFields(). You can modify the fields using an updateMemberFormFields method in an extension applied to Member - so all you need to do is create an extension/decorator applied to the Member class, and have an updateMemberFormFields method which replaces the Email field with an EmailField.

Avatar
Josua

8 March 2012 at 12:24am Community Member, 86 Posts

Hello Andrew!

Uhhhmmmm!! That sounds interesting.
I'm beginner in SilverStripe, but I will try to do what you tell me, I'll tell you something.
By the way, is there any easy way to integrate memberprofiles with the forum module?

Thanks you very much for your reply.

Regards,
Jose

Avatar
Josua

10 March 2012 at 3:29am (Last edited: 10 March 2012 7:34am), Community Member, 86 Posts

Hello Andrew!

I tried your instructions, but does not work:

MyMember.php

class MyMember extends DataObjectDecorator {
public function updateMemberFormFields(&$fields) {
$fields->removeByName('Email');
$fields->push(new EmailField('Email', 'Email address22'));
}

_config.php

Object::add_extension('Member', 'MyMember');

http://127.0.0.1/dev/build?flush=all

I have verified that the field has been changed, since it show 'Email address22', however, the field email continues to accept any text, it does not check to be a valid mail.

To verify that I had no problem in another part of my project I created a sample form (manually) that included a EmailField.
In that form everything works perfectly, and this field (EmailField) only accepts valid email formats, besides, in that form automatically works the javascript validation (client-side), while in the memberprofiles module it does not work.
It is obviously a problem of the memberprofiles module, not of my project.
Maybe I need to configure something else in the memberprofiles module?

What can be happening?
Do I have to do something more in order that it works?

Please, help, thanks,
Regards,
Jose

Avatar
Josua

11 March 2012 at 6:04am Community Member, 86 Posts

Hello Andrew!

I already have discovered what it is the problem for the which the EmailField control not work.
You have disabled the javascript validation in your MemberProfileValidator class.

   /**
    * JavaScript validation is disabled on profile forms.
    */
   public function javascript() {
      return null;
   }

The EmailField control only works if the Javascript is enabled.

Why you've disabled javascript validation for memberprofiles module ?
Is there a compelling reason ?

What can I do in order that the control Emailfield work correctly?

Thanks,
Regards,
Jose

Go to Top