I have a member type property drop down list on my edit member screen called domain which has a list of allowable domains ie google.com, umbraco.org etc
when the admin saves the member i would like to check the email address for the member ends in the same domain as the domain selected in the drop down list..
i was wondering how i could hook into the member save.. i have seen beforesave and aftersave but was wondering how i'd get access to the value of the dropdownlist if i was in an actionhelper class and if there was a way to do this..
actionhelper : applicationbase doesn't seem like the right approach..
Hi Tom, I'm not 100% sure what you are trying to do here but i think ApplicationBase may work for you.
Have a look at the below code:
using umbraco.cms.businesslogic.member; using umbraco.BusinessLogic;
namespace Core.Events { public class UmbracoEventHandler : ApplicationBase { public UmbracoEventHandler() { Member.AfterSave += new Member.SaveEventHandler(Member_AfterSave); }
void Member_AfterSave(Member sender, umbraco.cms.businesslogic.SaveEventArgs e) { Member m = new Member(sender.Id); //do what you want with the member and cancel the action if you want, depending on your checks //e.Cancel; } } }
if if was to use either the problem I have is acutally getting the value of the property from the form.. as in before save it wouldn't have been assigned to the member and after save it's too late..
so my scenario is a have a Member Type called SolutionUser which uses a drop down list and I'd need to retrieve the current value of that drop down list in one of those events.. and it's the retrieving that value that i am unsure of..
So you are creating a new member with type SolutionUser from within the Umbraco member console (entering email in the create dialog), then after creating the member you assign the drop down list value.
So by the time you even see the drop down list, the user is already created with an email? Is my understanding correct?
i was just starting to implement a custom validator but was wondering the best way to retrieve the member.. should i just use the id from the querystring as they do in the EditMember class ie: newMember(int.Parse(base.Request.QueryString["id"]));
@Slace - Great article! I did know that as soon as you set a property value, it saves, but didn't connect it to cancelling the event. Really good to know!!!
@Tom - I work for a company called Clarity Communications
Yeah like slace said create a custom datatype using the usercontrol wrapper, and handle validation in that.
Can you post a link where I can download the whole usercontrol, and i will have a look?
I think I fixed the canceling of events on Documents in 4.1, but I can't remember rightly, I'll have to look back into that section of the code one of these days :P
Edit Member Screen Custom Validation
Hi guys,
I have a member type property drop down list on my edit member screen called domain which has a list of allowable domains ie google.com, umbraco.org etc
when the admin saves the member i would like to check the email address for the member ends in the same domain as the domain selected in the drop down list..
i was wondering how i could hook into the member save.. i have seen beforesave and aftersave but was wondering how i'd get access to the value of the dropdownlist if i was in an actionhelper class and if there was a way to do this..
actionhelper : applicationbase doesn't seem like the right approach..
cheers,
Tom
Hi Tom,
I'm not 100% sure what you are trying to do here but i think ApplicationBase may work for you.
Have a look at the below code:
using umbraco.cms.businesslogic.member;
using umbraco.BusinessLogic;
namespace Core.Events
{
public class UmbracoEventHandler : ApplicationBase
{
public UmbracoEventHandler()
{
Member.AfterSave += new Member.SaveEventHandler(Member_AfterSave);
}
void Member_AfterSave(Member sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
Member m = new Member(sender.Id);
//do what you want with the member and cancel the action if you want, depending on your checks
//e.Cancel;
}
}
}
Cheers,
Neil
You would actually use before save, not after save for what you are trying to do.
Also can you please mark the post as the solution if it solves your problem :)
Hi Neil,
if if was to use either the problem I have is acutally getting the value of the property from the form.. as in before save it wouldn't have been assigned to the member and after save it's too late..
so my scenario is a have a Member Type called SolutionUser which uses a drop down list and I'd need to retrieve the current value of that drop down list in one of those events.. and it's the retrieving that value that i am unsure of..
Regards,
Tom
Hi Tom,
So you are creating a new member with type SolutionUser from within the Umbraco member console (entering email in the create dialog), then after creating the member you assign the drop down list value.
So by the time you even see the drop down list, the user is already created with an email? Is my understanding correct?
Cheers,
Neil
Hi Niel,
yes your understanding is completely correct!
doh! can't edit the html in the reply and add a link to an image!
the screenshot of that form is there
thanks for your help neil!
also is there any way to delete posts? like those last 2?
doh! can't edit the html in the reply and add a link to an image!
the screenshot of that form is there
thanks for your help neil!
also is there any way to delete posts? like those last 2?
also im my member before save event handler if i set e.Cancel = true it still goes ahead with the save! strange...
Cool cool. I have an idea :) I will write it up at lunch time.
thanks so much Neil!
so perth hey! whereabouts do you work?
Just FYI guys, BeforeSave wont actually allow you to prevent the save operation, see my blog post here:http://www.aaron-powell.com/blog/july-2009/the-great-umbraco-api-misconception.aspx
Your best solution is to create a custom drop down list data type which you have your own validation logic.
Hi Slace,
thanks for letting us know!
i was just starting to implement a custom validator but was wondering the best way to retrieve the member.. should i just use the id from the querystring as they do in the EditMember class ie: new Member(int.Parse(base.Request.QueryString["id"]));
Cheers,
Tom
protected void ValidateMemberDomainDropDown(object source, ServerValidateEventArgs args)
{
args.IsValid = true;
var memberDomainString = MemberDomainDropDownList.SelectedItem.Text;
if (!string.IsNullOrEmpty(memberDomainString))
{
string currentPage = Page.Request.Path.ToLower().Replace((umbraco.GlobalSettings.Path + "/").ToLower(), "");
if (currentPage == "members/editmember.aspx")
{
TextBox memberLoginTextBox = (TextBox)Page.Master.FindControl("body").FindControl("plc").FindControl("TabView1").Controls[0].Controls[0].Controls[4].FindControl("ctl11");
if (memberLoginTextBox != null)
{
var domainFromEmailAddress = SecurityHelper.GetDomain(memberLoginTextBox.Text);
if (!string.Equals(memberDomainString, domainFromEmailAddress, StringComparison.InvariantCultureIgnoreCase))
{
args.IsValid = false;
}
}
}
}
}
Here's what i did.
very wierd.. even if args.IsValid is set to false i still see the balloon pop up saying "Member Saved Successfully" - any hints on that one?
@Slace - Great article! I did know that as soon as you set a property value, it saves, but didn't connect it to cancelling the event. Really good to know!!!
@Tom - I work for a company called Clarity Communications
Yeah like slace said create a custom datatype using the usercontrol wrapper, and handle validation in that.
Can you post a link where I can download the whole usercontrol, and i will have a look?
Cheers,
Neil
I think I fixed the canceling of events on Documents in 4.1, but I can't remember rightly, I'll have to look back into that section of the code one of these days :P
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.