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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Memberprofiles - Check email field only accept valid email


Go to End


12 Posts   5493 Views

Avatar
Josua

Community Member, 87 Posts

1 March 2012 at 9:13am

Edited: 01/03/2012 9:39am

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

Community Member, 87 Posts

7 March 2012 at 6:38am

Hi all!

Does anyone know how to do this? :(

Thanks,
Regards,
Jose

Avatar
novaweb

Community Member, 116 Posts

7 March 2012 at 12:18pm

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

Community Member, 87 Posts

7 March 2012 at 8:44pm

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

Community Member, 244 Posts

7 March 2012 at 9:23pm

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

Community Member, 87 Posts

8 March 2012 at 12:24am

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

Community Member, 87 Posts

10 March 2012 at 3:29am

Edited: 10/03/2012 7:34am

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

Community Member, 87 Posts

11 March 2012 at 6:04am

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