Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 00:46
    Tom
    0

    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

  • Neil Campbell 58 posts 182 karma points
    Feb 18, 2010 @ 02:23
    Neil Campbell
    0

    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

  • Neil Campbell 58 posts 182 karma points
    Feb 18, 2010 @ 02:26
    Neil Campbell
    0

    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 :)

  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 03:08
    Tom
    0

    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

  • Neil Campbell 58 posts 182 karma points
    Feb 18, 2010 @ 03:28
    Neil Campbell
    0

    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

     

  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 03:40
    Tom
    0

    Hi Niel,

    yes your understanding is completely correct!


  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 03:41
    Tom
    0

  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 03:41
    Tom
    0

    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?

  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 03:44
    Tom
    0

    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...

     

  • Neil Campbell 58 posts 182 karma points
    Feb 18, 2010 @ 03:48
    Neil Campbell
    0

    Cool cool. I have an idea :) I will write it up at lunch time.

  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 03:51
    Tom
    0

    thanks so much Neil!

     

    so perth hey! whereabouts do you work?

     

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Feb 18, 2010 @ 04:24
    Aaron Powell
    1

    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.

  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 04:46
    Tom
    0

    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

  • Tom 713 posts 952 karma points
    Feb 18, 2010 @ 05:29
    Tom
    0

    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?

  • Neil Campbell 58 posts 182 karma points
    Feb 18, 2010 @ 05:51
    Neil Campbell
    0

    @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

     

     

     

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Feb 18, 2010 @ 07:53
    Aaron Powell
    0

    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

  • 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.

Please Sign in or register to post replies