Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Mar 16, 2011 @ 03:57
    syn-rg
    0

    Email this page sends without valid email address

    I have a very old "Email this page" xslt that is using Sendmail to send the page link. However the form sends even without a valid email address.

    Can anyone suggest a way I can fix this without having to create a new xslt page, or has anyone got a simple "Email this page" xslt form that checks for a valid email address?

    Cheers,
    JV

    Here's my code:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE xsl:Stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library"
      xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions"
        exclude-result-prefixes="msxml umbraco.library">

      <xsl:output method="xml" omit-xml-declaration="yes" />
      <xsl:param name="currentPage" />
      <xsl:variable name="source" select="/macro/source" />
      <xsl:variable name="msgSuccess" select="'Your email has been sent succesfully'" />
      <xsl:variable name="msgErrMsg" select="'Please enter a name and valid email'" />
      <xsl:variable name="msgErrMsgOpt" select="'Email failed!'" />
      <!-- fields in form - grab them -->
      <xsl:variable name="fname" select="umbraco.library:RequestForm('emailPageFirstName')" />
      <xsl:variable name="femail" select="umbraco.library:RequestForm('emailPageEmail')" />
      <xsl:variable name="fcomments" select="umbraco.library:RequestForm('emailPageComments')" />  <!-- submit button -->
      <xsl:variable name="submitted" select="umbraco.library:RequestForm('butSubmit')" />

      <!-- create your page validation -->
      <xsl:variable name="error">
        <xsl:choose>
          <xsl:when test="string($fname) = '' or string($fname) = 'First name'
                        or string($femail) = '' or string($femail) = 'Email'">1</xsl:when>
          <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:template match="/">
    <a class="email_page" href="#" title="Email this page">Email this page</a>
        <!-- figure out if the page is displayed for the first time, is submitted or is in any errorstate -->
        <xsl:variable name="pagePARENT">
          <xsl:for-each select="$currentPage/ancestor-or-self::node">
            /<xsl:value-of select="@urlName"/>
          </xsl:for-each>
        </xsl:variable>
        <xsl:variable name="pageFullUrl">
          <xsl:value-of select="umbraco.library:Replace($pagePARENT, 'home/', '')"/>.aspx
        </xsl:variable>
        <xsl:choose>
          <xsl:when test="$error='1' or $submitted=''">
              <div id="page_tools_email">
                <input type="text" name="emailPageFirstName" id="emailPageFirstName" title="First name" value="First name" onfocus="if(this.value == 'First name') this.value = '';" onblur="if(this.value == '') this.value = 'First name';" />
                <br />
                <input type="text" name="emailPageEmail" id="emailPageEmail" title="Email address" value="Email address" onfocus="if(this.value == 'Email address') this.value = '';" onblur="if(this.value == '') this.value = 'Email address';" />
                <br />
                <textarea rows="2" cols="2" id="emailPageComments" name="emailPageComments" title="comments" class="prefill_text" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value == '') this.value = 'Comments';" >Comments</textarea>
                <span id="charlimitinfo2">Write your message within <span>130</span> characters.</span>
                <br/>
                <div id="email_btn">
                  <input class="button" type="submit" value="send" name="butSubmit" id="butSubmit" />
                </div>
            </div>
      <xsl:if test="$error='1' and $submitted!=''">
        <div class="errmsg">
          <xsl:value-of select="$msgErrMsg" />  
        </div>
            </xsl:if>
           
          </xsl:when>
          <xsl:when test="$error='0' and $submitted='send'">
            <!-- all is sweet - compose email - remember to use &lt; -->
      <xsl:variable name="fullPathUrlPort" ><xsl:if test="umbraco.library:RequestServerVariables('SERVER_PORT')!='' or umbraco.library:RequestServerVariables('SERVER_PORT')!='80'">:<xsl:value-of select="umbraco.library:RequestServerVariables('SERVER_PORT')" /></xsl:if>  </xsl:variable>
      <xsl:variable name="fullPathUrl" >
        http://<xsl:value-of select="umbraco.library:RequestServerVariables('SERVER_NAME')"/><xsl:value-of select="$fullPathUrlPort" /><xsl:value-of select="umbraco.library:NiceUrl($currentPage/@id)" />
      </xsl:variable>

            <xsl:variable name="htmlmail" >
    &lt;p&gt;Hello&nbsp;<xsl:value-of select="$fname"/>,&lt;/p&gt;
    &lt;p&gt;You have been sent the following link on the ISIS website: &lt;a href='<xsl:value-of select="$fullPathUrl" />' target='_blank' &gt;<xsl:value-of select="$currentPage/@nodeName"/>&lt;/a>&lt;/p&gt;
    &lt;p&gt;Please copy and paste the following url if above link does not work:&lt;/p&gt;
    &lt;p&gt;&lt;a href='<xsl:value-of select="$fullPathUrl" />' &gt;<xsl:value-of select="$fullPathUrl"/>&lt;/a>&lt;/p&gt;
    &lt;p&gt;Comments from your friend: &lt;strong&gt;<xsl:value-of select="$fcomments"/>&lt;/strong&gt;&lt;/p&gt;
    &lt;p&gt;© ISIS&lt;/p&gt;
            </xsl:variable>


            <!-- Send Mail -->
            <xsl:variable name="smtpresult" select="umbraco.library:SendMail('[email protected]', $femail, 'ISIS - Your friend has referred this page.', $htmlmail, 'true')" />
            <div class="success">
              <xsl:value-of select="$msgSuccess" />
            </div>
            <!-- After sending Reload the Page -->


          </xsl:when>
        </xsl:choose>
      </xsl:template>
    </xsl:stylesheet>
  • syn-rg 282 posts 425 karma points
    Mar 16, 2011 @ 06:19
    syn-rg
    0

    I've created a HTML version using jQuery for validation, which I'm going to try and implement into my existing XSLT:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jQuery Example - Check Passwords Match</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    var $loading = $('<div class="loading"><img src="/media/images/loading.gif" alt="" /></div>');
    $(".default").each(function(){
    var defaultVal = $(this).attr('title');
    $(this).focus(function(){
    if ($(this).val() == defaultVal){
    $(this).removeClass('active').val('');
    }
    });
    $(this).blur(function() {
    if ($(this).val() == ''){
    $(this).addClass('active').val(defaultVal);
    }
    })
    .blur().addClass('active');
    });
    $('.btn-submit').click(function(e){
    var $formId = $(this).parents('form');
    var formAction = $formId.attr('action');
    defaulttextRemove();
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    $('li',$formId).removeClass('error');
    $('span.error').remove();
    $('.required',$formId).each(function(){
    var inputVal = $(this).val();
    var $parentTag = $(this).parent();
    if(inputVal == ''){
    $parentTag.addClass('error').append('<span class="error">Required field</span>');
    }
    if($(this).hasClass('email') == true){
    if(!emailReg.test(inputVal)){
    $parentTag.addClass('error').append('<span class="error">Enter a valid email address.</span>');
    }
    }
    });
    if ($('span.error').length == "0") {
    $formId.append($loading.clone());
    $('fieldset',$formId).hide();
    $.post(formAction, $formId.serialize(),function(data){
    $('.loading').remove();
    $formId.append(data).fadeIn();
    });
    }
    e.preventDefault();
    });
    });
    function defaulttextRemove(){
    $('.default').each(function(){
    var defaultVal = $(this).attr('title');
    if ($(this).val() == defaultVal){
    $(this).val('');
    }
    });
    }
    function limitChars(textid, limit, infodiv)
    {
    var text = $('#'+textid).val();
    var textlength = text.length;
    if(textlength > limit)
    {
    $('#' + infodiv).html('<strong>You cannot write more then <span>'+limit+'</span> characters!</strong>');
    $('#'+textid).val(text.substr(0,limit));
    return false;
    }
    else
    {
    $('#' + infodiv).html('You have <span>'+ (limit - textlength) +'</span> characters left.');
    return true;
    }
    }

    $(function(){
    $('#input-message').keyup(function(){
    limitChars('input-message', 130, 'charlimitinfo2');
    })
    });
    </script>
    <style type="text/css">
    /*Form styles*/
    .styled {
    font-family: Arial, sans-serif;
    }
    .styled fieldset {
    border: 1px solid #ccc;
    padding: 10px;
    }
    .styled fieldset legend {
    font-size: 14px;
    font-weight: bold;
    color: #000;
    text-transform: capitalize;
    padding: 5px 10px;
    background: #fff;
    display: block;
    margin-bottom: 0;
    border: 1px solid #ccc;
    }
    .styled fieldset ol, .styled fieldset ol li {
    list-style: none;
    }
    .styled fieldset li.form-row {
    margin-bottom: 3px;
    padding: 2px 0;
    width: 100%;
    overflow: hidden;
    position: relative;
    }
    .styled label {
    font-size: 12px;
    display: block;
    font-weight: bold;
    float: left;
    width: 100px;
    margin-left: 5px;
    line-height: 24px;
    }
    .styled input.text-input, .styled .text-area {
    font-family: Arial, sans-serif;
    background: #fefefe;
    border-top: 1px solid #909090;
    border-right: 1px solid #cecece;
    border-bottom: 1px solid #e1e1e1;
    border-left: 1px solid #bbb;
    padding: 3px;
    width: 220px;
    font-size: 12px;
    }
    .styled input.text-input.default.active, .styled .text-area.default.active {
    color: #666666;
    font-style: italic;
    }
    .styled fieldset li.button-row {
    margin-bottom: 0;
    padding: 2px 5px;
    }
    form input.btn-submit {
    padding: 3px 7px;
    font-family: Arial, sans-serif;
    color: #000;
    font-weight: bold;
    border: 1px solid #000;
    background: #FFE220;
    font-size: 12px;
    }
    /* Form Validation */
    .styled span.error {
    font-size: 11px;
    background: none;
    display: block;
    padding: 2px;
    text-align: left;
    }
    .styled fieldset li.error {
    color: #D8000C;
    background: #fff0f0 url(../media/images/checkers.png) repeat;
    border: 1px solid #f9c7c7;
    padding: 5px 0;
    }
    .styled fieldset li.error label {
    text-align: left;
    }
    /* Specific Form Rules */
    #form-contact {
    width: 360px;
    margin: 0 auto;
    }
    .success {
    order: 1px solid;
    margin: 0;
    padding: 10px;
    text-align: center;
    color: #4F8A10;
    background-color: #ebf6d9;
    border-color: #DFF2BF;
    }
    </style>
    </head>
    <body id="demo">
    <form id="form-contact" class="styled" action="test_submit.htm" method="post">
    <fieldset>
    <ol>
    <li class="form-row">
    <input id="input-name" type="text" class="text-input required default" name="name" value="" title="Enter your friends first name" />
    </li>
    <li class="form-row">
    <input id="input-email" type="text" class="text-input required email default" name="email" value="" title="Enter your friends email address" />
    </li>
    <li class="form-row">
    <textarea id="input-message" class="text-area required default" name="message" cols="2" rows="4" title="Enter a comment"></textarea>
    <span id="charlimitinfo2" style="float:left; font-size:10px;">Write your message within <span>130</span> characters.</span>
    </li>
    <li class="button-row text-right">
    <input class="btn-submit" type="submit" value="send" name="submit" />
    </li>
    </ol>
    </fieldset>
    </form>
    </body>
    </html>
  • 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.

    Continue discussion

Please Sign in or register to post replies