Search

I’m working on a little side project due to having a regular request from my clients to implement some manner of spam protection. I’m looking for a method that could work on sites of all sizes and the best option I’ve found is the textCAPTCHA.

The problem is, I’m having trouble integrating it.

The XSLT I’m using for my page is:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="../utilities/master.xsl"/>

<xsl:template match="data">
    <div class="contact-form">
        <h2>Contact Form</h2>
        <form action="" method="post">
            <xsl:for-each select="events/save-message">
                <xsl:choose>
                    <xsl:when test="@result = 'success'">
                        <div class="result">
                            <h3>Your message was sent successfully!</h3>
                            <p>I try my best to resond to every e-mail I get in a timely manner so you’ll be hearing form me soon! While you wait, why not check out my work?</p>
                            <p><a rel="jump-link" href="#portfolio" title="Jump to the Portfolio section">View My Projects</a></p>
                        </div>
                    </xsl:when>
                    <xsl:otherwise>
                        <div class="result">
                            <h3>Your message had an error!</h3>
                            <p>Something was missing from your e-mail or didn’t sit well with my site. Let’s just cut out the middle man, shall we?</p>
                            <p>My e-mail is <a rel="email" href="mailto:doug@designbyadmiral.com" title="Email doug directly">doug@designbyadmiral.com</a>.</p>
                        </div>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
            <fieldset>
                <h3>Your contact information</h3>
                <p>
                    <label id="contact-name-label" for="contact-name">Name</label>
                    <input id="contact-name" class="required" type="text" name="fields[name]" value="{events/save-message/post-values/name}" />
                </p>
                <p>
                    <label id="contact-email-label" for="contact-email">Email</label>
                    <input id="contact-email"  class="required email" type="text" name="fields[email]" value="{events/save-message/post-values/email}" />
                </p>
                <h3>What can I do for you?</h3>
                <p>
                    <label id="contact-subject-label" for="contact-subject">Subject</label>
                    <xsl:choose>
                        <xsl:when test="events/save-message/post-values/subject">
                            <input id="contact-subject" class="required" type="text" name="fields[subject]" value="{events/save-message/post-values/subject}" />
                        </xsl:when>
                        <xsl:otherwise>
                            <input id="contact-subject" class="required" type="text" name="fields[subject]" value="General Enquiry" />
                        </xsl:otherwise>
                    </xsl:choose>
                </p>
                <h3>Are you human?</h3>
                <p>
                    <label id="contact-message-label" for="contact-message">Message</label>
                    <textarea id="contact-message" class="required" name="fields[message]" rows="5" cols="21"><xsl:value-of select="events/save-message/post-values/message" /></textarea>
                </p>
                <p>
                    <label id="contact-captcha-title" for="contact-captcha"><xsl:value-of select="captcha/captcha/question"/></label>
                    <input id="contact-captcha" class="required" type="text" name="fields[answer]" />
                    <xsl:for-each select="captcha/captcha/answer">
                        <input type="hidden" name="fields[captcha{position()}]" value="{.}" />  
                    </xsl:for-each>
                </p>
                <input name="send-email[recipient]" value="{website-owner/author/username}" type="hidden" />
                <input name="send-email[sender-email]" value="fields[email]" type="hidden" />
                <input name="send-email[sender-name]" value="fields[name]" type="hidden" />
                <input name="send-email[subject]" value="fields[subject]" type="hidden" />
                <input name="send-email[body]" value="fields[message],fields[subject],fields[email],fields[name]" type="hidden" />
                <input name="send-email[answer]" value="fields[answer]" type="hidden" />
                    <xsl:for-each select="captcha/captcha/answer">
                        <input name="send-email[captcha{position()}]" value="fields[captcha{position()}]" type="hidden" />  
                    </xsl:for-each>
                <p id="submit-button"><input id="submit" type="submit" name="action[save-message]" value="Send" /></p>
            </fieldset>
        </form>
    </div>
</xsl:template>

</xsl:stylesheet>

Towards the end you can see where I iterate through the returned XML and generate the MD5 answers to test against. The problem is, I’m having an issue getting the test part working and my guess is I have to make changes in the event.save_message.php file, right?

I tried changing the default trigger function to this:

protected function __trigger(){
    $answer = $_POST['answer'];
    $captcha = $_POST['captcha1'];
    if(md5(strtolower($answer))==$captcha){
        include(TOOLKIT . '/events/event.section.php');
        return $result;
    }
}

But I’m getting not success or fail response so I’m not sure what’s going on. Also, my PHP is almost non-existant so I’m pretty much guessing.

Can anyone point me in the right direction?

I’m still pretty stuck on this… Can anyone give me a hand?

I’ve only had a brief look but you might try something like

protected function __trigger(){
    $answer = $_POST['answer'];
    $captcha = $_POST['captcha1'];
    if(md5(strtolower($answer))==$captcha){
        include(TOOLKIT . '/events/event.section.php');
    }
    else {
        $result = new XMLElement(self::ROOTELEMENT);
        $result->setAttribute('result', 'error');           
        $result->appendChild(new XMLElement('message', __('The Captcha text you've entered was incorrect..')));
        $result->appendChild(buildFilterElement('textcaptcha', 'failed'));
    }
    return $result;
}

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details