Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Can someone recommend a customizable contact form, please? Reply To: Can someone recommend a customizable contact form, please?

#177747
__
Participant

I found the problem, a silly and obvious mistake on my part. There needs to be a hyphen or something to style the messages.

That’s actually something I changed in our last post. Sorry for the confusion. Previously, it was class="cform notice" —two class names— which you would select like .cform.notice (no space). After changing it, it is class="cform-notice" —one class name— which, as you figured out, is selected like .cform-notice.

I prefer making changes in the CSS and not using HTML markup withing the message.

Well, we didn’t need to make that last change at all, then. But it doesn’t hurt anything, and gives you the flexibility if you want to add HTML in the future.

Now to have variable answers to the anti-spam question, such as Green, green, & 12, Twelve, twelve.

First, for any questions that you want to have multiple answers, we’ll just add all acceptable values as an array.

protected $_antispam = array(
    // instead of this:
    //"What is 1+1?" => "2"
    // we'll do this:
    "What is 1+1?" => array( "2","two" )

    // etc. ...
);

When you define values, it is best to use all lowercase letters (see below*).

Then, in order to use that, we need to change the validation method. In_validateAntispam, find this line (~398):

&& $this->_antispam[$_SESSION[__CLASS__]["antispam"]] === $value

and change it to:

&& in_array( $value, (array)$this->_antispam[$_SESSION[__CLASS__]["antispam"]] )

What we’re doing here is, instead of making sure the provided value matches, we’re making sure it matches one of the values in the array of acceptable answers.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~
* I am also adding another option: case-insensitivity. This way, “two” or “Two” or “tWo” (etc.) will all validate. If you don’t want it, set the property $_options["value.ci"] to false.

Inside the validate method, we’ll add this:

            if( $this->_option["value.ci"] ){
                $value = mb_strtolower( $value );
            }

This isn’t really a big change, so don’t worry too much about it. It’s something I probably should have thought of when we wrote it in the first place.

The gist is up-to-date. It should work just fine, but I haven’t had a chance to test it yet. I’ll get back to you on that, or let me know if you find any problems.