Copied to clipboard

Flag this post as spam?

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


  • Dan 1285 posts 3917 karma points c-trib
    Nov 10, 2009 @ 15:53
    Dan
    0

    Recommend to a friend

    Hi,

    I'm implementing a simple 'recommend to a friend' feature on my Umbraco site.  When the user clicks the 'recommend' icon, a modal window is opened which contains a form containing three input fields: 'your email address', 'friends email address' and 'message' together with a hidden field containing the URL of the current page.

    Now I'm stuck how to get these details emailed.  I'm thinking the simplest way to do this would be to use AJAX/JQuery to post the form input values to a 'secret' asp.net page, which would handle the email then return a confirmation message to JQuery.

    Is this doable?  If so, does anyone have a simple email script they could show me which could do this?  I'm an ASP.NET newby and the way it interacts with Umbraco makes my head spin a little!

    Thanks all...

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Nov 10, 2009 @ 16:00
    Warren Buckley
    0

    Hiya Dan to use AJAX/JQuery with umbraco best way is to use /base in my opinion.
    Check out the /base section on the WIKI at - http://our.umbraco.org/wiki/reference/umbraco-base

    Or another idea is that there are plenty of jQuery dialog plugins that allow you to use an iFrame, so in this case you could use an alternative template to do this as well.

    For example:
    /email-a-friend-template-alias.aspx?pageID=1234

    I have an email a friend fucntion in my Creative Website Package that you could look at and pull apart but it does not currently setup with a dialog popup.

    http://our.umbraco.org/projects/creative-website-starter-%28cws%29

    Warren :)

     

  • Dan 1285 posts 3917 karma points c-trib
    Nov 10, 2009 @ 16:30
    Dan
    0

    Thanks Warren, I've not come across base before, but it certainly looks interesting.

    I've not installed CWS just yet as my project was based on Runway, which was easier for me to understand at the time of starting the project, but I'm kind of regretting not basing it on CWS as it looks like you've covered a lot of the functionality I'm struggling to implement (RSS feeds, contact forms etc).

    What I'm looking for specifically with this though is a way to capture form data and send an email with ASP.NET which uses the Umbraco config settings.  The front-end stuff is done (the modal, the form and the JQuery to post the data to a page and output a returned text string), I just need a means of collecting and emailing the data in ASP.NET.  I could do it in classic ASP by creating a page called 'send-email.asp' and adding it as a reserved URL in web.config.  JQuery would then post data to the page, which contains the following code (in it's absolute most basic, dirty, unvalidated form):

    <%
    strEmailTo = request("email-to")
    strEmailFrom = request("email-from")
    strMessage = request("message")
    strURL = request("url")

    Set myMail = CreateObject("CDO.Message")
    myMail.Subject = "I thought you'd be interested in this"
    myMail.From = strEmailFrom
    myMail.To = strEmailTo
    myMail.TextBody = "I thought you'd be interested in this web page: " & strURL
    myMail.Sendset myMail = nothing

    response.write("Email sent!")
    %>

    I'm just wondering if it's possible to do something simple like this in ASP.NET as I'd prefer to learn how, rather than fleeing to the safe territory of classic ASP which I know very well.

    Is there a particular file I can look at in a CWS installation which will show me how to do this?  I'm very easily confused at the moment as I'm a real beginner at both .NET and Umbraco, so am still getting my head around how it works and how it all fits together.

    Thanks

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Nov 10, 2009 @ 17:16
    Warren Buckley
    0

    Ah OK Dan,
    Then CWS is definately for you, especially if your a beginner to .NET & umbraco as my code is nicely commented and
    should be easy to follow along with.

    I would recommend a new clean installation of umbraco 4.0.2.1 and not to install runway but to install CWS instead.

    In asp.net you won't need a <form> tag with a url to page to send it to, instead you can have .net usercontrol which in this case is an email a friend usercontrol which has some asp.net form fields and a button which when clicks runs some code.

    So you wont need to send it off to a specific page or URL with the code in to do this, unless you preffered to do this then you could do this with /base.

    Here are some direct links to the source code running of CodePlex

    EmailAFriendForm.ascx (usercontrol)
    http://umbracocws.codeplex.com/SourceControl/changeset/view/24171#591178

    EmailAFriendForm.ascx.cs (usercontrol codebehind)
    http://umbracocws.codeplex.com/SourceControl/changeset/view/24171#591179

    I presume you have a copy of Visual Studio or Visual Studio Express? If not I recommend you gof off and download a free copy of Visual Studio Express.

    Warren :)

  • Dan 1285 posts 3917 karma points c-trib
    Nov 10, 2009 @ 17:52
    Dan
    0

    Thanks Warren.  I think I get the principle now.  I'm just confused as to how the .ascx is integrated into my template?  Currently, the form I have is simply an HTML form in a modal div in one of my template files.  Are template files in Umbraco ascx files?

    Thanks again - I know this must be trivial, but it's just difficult getting my head around it.

  • Dan 1285 posts 3917 karma points c-trib
    Nov 10, 2009 @ 17:53
    Dan
    0

    I guess what I mean above is can I add ASP.NET form controls into my Umbraco templates?

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Nov 10, 2009 @ 18:53
    Warren Buckley
    0

    Basically you need to look at macros in the developer section of my CWS package.
    A macro can be an XSLT file or .NET usercontrol.
    You then insert the macro onto an ASP.NET masterpage (template) where you want the code to be inserted.

    http://umbracocws.codeplex.com/SourceControl/changeset/view/24171#591038

  • Gary 20 posts 44 karma points
    Nov 18, 2009 @ 02:51
    Gary
    0

    Hi Dan,

    I've used Warren's CWS kit and it does indeed do what you want. Just look into the code and make changes where necessary! You can install CWS on a test server and poke around with it and once comfortable recreate the code without having to have CWS installed. Great work Warren by the way!

    Anyway, what I was meaning to add (from a admin point of view) is to make sure you have a method of controlling the access to the form. Sending an email using the entered details could leed to the service being abused (especially if you have some user editable "body") and if that happens you could get blacklisted by anti-spam services. Just give it a thought.

     

  • Digby 23 posts 43 karma points
    Nov 18, 2009 @ 06:52
    Digby
    0

    Hi All,

    Following on from Garys warning. We have just experienced the Recommend a Friend abuse mentioned.

    The spammer used our form to send a small number of emails, we guess so as not to attract our attention. They then repeated this 3 weeks later on which occassion we did notice and removed the facility until we add some captcha mechanism.

    tread carefully.

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Nov 18, 2009 @ 09:37
    Warren Buckley
    0

    Hiya Digby,
    Unfortunately practically any web form is open to attack by spammers really.

    Thinking about the recommend a friend form it should in theory have some form of spam protection to avoid it being abused.

    If you think it is something I should work on CWS, please report a bug/issue on codeplex for me so I don't forget.

    http://umbracocws.codeplex.com/WorkItem/AdvancedList.aspx

    Thanks,
    Warren

  • Gary 20 posts 44 karma points
    Nov 18, 2009 @ 23:39
    Gary
    0

    Hi Warren,

    I don't know if you need to add it into your CWS package. It depends on whether you're aligning your package to be used as a learning tool or a full website building tool. I took it for the former and basically used your work to give me an idea about how Umbraco worked. Adding a spam protection tool would probably make it a little too complex. Maybe a side project?

    FYI, I originally added a reCaptcha control into the Email a friend page but this was rejected bythe powers that be as it was too "complex" ie words were a little to abstract and long. I ended up creating my own captcha image using some code based on a blog which was "good enough". Method a requires user registration and would be hard to package. Method b requires adding an aspx page to the Reserved URLs which I'm not sure you can package either.

    I think that somewhere on the email a friend page (maybe on the settings to make a note (label) that the page may be open to abuse and that it is worth considering adding some anti spam mechanisms before adding to a live site.

     

  • Nikolas van Etten 202 posts 162 karma points
    Nov 19, 2009 @ 01:20
    Nikolas van Etten
    0

    Perhaps a bit off-topic, but why spend time doing what's already been done? For me AddThis works perfect and it does not only give you the email a friend option, but tons of other options as well and it's easy to setup as you want it. 

  • Gary 20 posts 44 karma points
    Nov 19, 2009 @ 05:06
    Gary
    0

    While AddThis is indeed cool, it depends on who the sites are being developed for. Some people prefer not to rely on 3rd party tools for whatever the reason (privacy, reliability etc). It doesn't matter how good the service is, if it's policy not to use it then you need to explore other methods!

Please Sign in or register to post replies

Write your reply to:

Draft