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?

#169094
__
Participant

Thus far I understand most of what’s being done and what I don’t I’ve googled…

Great!
(BTW, I haven’t forgotten you; I’ve just been waiting for your responses/questions before moving on to each new part.)

important: I have fixed some typos in the code so far. (Among other things, I missed a few %s in our html template, and misspelled openssl_random_pseudo_bytes). Make sure you test with a fresh copy.

(gist updated.)

You’re ready for a quick test, now. include (or copy+paste) the class definition into your php script, and run the following code:

$contact = new contactMichael1961;
print "<pre>".htmlspecialchars( $contact->htmlMarkup() );

This should show you some nice HTML form markup, like so:

<form class=michael1961 action=? method=POST>
    <fieldset>
        <legend>Contact Us</legend>
        <label class=required>
            Your Name: <input name=name required value="">
        </label>
        <label class=required>
            Email Address: <input name=email type=email required value="">
        </label>
        <label>
            Send To:
            <select required>
                <option value>please select…</option>
                <option>display name</option>
            </select>
        </label>
        <label>
            Message: <textarea name=message>""</textarea>
        </label>
        <fieldset class=antispam>
            <legend>
                Anti-Spam Question
                <a href=# title="Please answer the question below. This is used to help prevent spam.">(why?)</a>
            </legend>
            <label class=required>
                Are you a Robot? <input name=spam required>
            </label>
            <label class=blank>
                (leave this field blank) <input name=required>
                <input name=token type=hidden value=e2c6ae19913cec1b60d7d36ea7a0561c>
            </label>
        </fieldset>
        <label><input type=submit value=Submit></label>
    </fieldset>
</form>

If you want to see the actual form, remove the <pre> tag and the call to htmlspecialchars. We can also write a quick method that gets the form’s css for us:

public function cssStyle(){
    return "<style>{$this->_cssRules}</style>";
}

Now, try:

<?php

include "path/to/contactMichael1961.php";
$contact = new contactMichael1961;
print $contact->cssStyle();
print $contact->htmlMarkup();

Should give you something like:

example output