Archive for the ‘FCF Script Help’ Category

Send Contact form to chosen department email

Wednesday, September 5th, 2007

I recently had the following question from a FCF user:

QUESTION

I would love to use your form in a website i am working on at the moment. But i want to be able to let the user select which department to send the email to rather than a single fixed email address. Is this possible?

ANSWER

Yes it is possible with a few modification. This modification is a little harder to follow than any previous one, but I’m sure you will get on just fine. Ready? good, now follow the steps below.

Step One: Setting up the Configuration

Open config.php in your favorite text/script editor.

Step Two:

Go-to line number 31 (or there abouts), look for the following line of code:


$email_it_to = "enter_your_email_address_in_here";

Step Three:

We need to update this line to support multiple email addresses, change the above line to:


$email_it_to = array("department1@yoursite.com", "department2@yoursite.com", "department3@yoursite.com");

The above now supports 3 email options (change the email address as you like) - you can add as many as you like (just separate the by a comma and have the email address enclosed in double quotes as above). We now have an array of email addresses.

Step Four:

Save config.php, we are finished with that file.

Step Five: Updating your Form

Open form.php in your favorite text/script editor.

Step Six:

Go-to line number 47 (or there abouts), look for the following lines of code:


<div class="r">
<label for="fullname" class="req">Full Name: <em>*</em></label>

Step Seven:

Directly above line 47, enter the following code:


<div class="r">
<label for="department" class="req">Department: <em>*</em></label>
<span class="f">
<select name="department" id="department">
<option value="">Please Select</option>
<option value="0">Department A</option>
<option value="1">Department B</option>
<option value="2">Department C</option>
</select>
</span>
</div>

You must now edit the above code to match your array. For example, in your array of emails address which you created in config.php enter the description in the above code. So if the first email address is somedepartment@somedomain.com, enter the department name within the option above replacing ‘Department A’. Do this for each email address you have in your list. Keep the option value as numbers incrementing from 0 (these will correspond the the email array element).

Step Eight: Setting up the Client-Side validation for your new form field

Go-to line 36 in form.php (or there abouts), look for the following line of code:


required.add('answer_out', 'NUMERIC');

Create a new line just below line 36 and enter the following:


required.add('department', 'NOT_EMPTY');

Step Nine:

Save form.php, we are finished with that file.

Step Ten: Setting up the Server-Side validation for your new form field

Open process_form.php in your favorite text/script editor.

Step Eleven:

Go-to line 89 in process_form.php (or there abouts), look for the following line of code:


$reqobj->add("answer_out","NUMERIC");

Create a new line just below line 89 and enter the following:


$reqobj->add("department","NOT_EMPTY");

Step Twelve: Sending the email to the correct department

Go-to line 164 in process_form.php (or there abouts), look for the following line of code:


@mail($email_it_to, $email_subject, $email_message, $headers);

Edit the above to match the following:


$email_item = $_POST['department'];
@mail($email_it_to[$email_item], $email_subject, $email_message, $headers);

Step Thirteen: Saving your files

Save process_form.php.

Now upload all 3 changed scripts, we have made all required changes!

NOTE: Sometimes the code presented in this blog will render slightly wacky (due to the wordpress cms limitations) - please let me know if you spot any errors.

Change Contact Form CAPTCHA Question

Wednesday, August 29th, 2007

I recently had the following question from a FCF user:

QUESTION

Hi, I’d like to either simplify that math question or change it to something different. How can I do this?

ANSWER

Luckily the script is build to allow you to do this very easily. To simplify the math question, follow these simple steps.

Step One:

Open config.php in your favorite text/script editor.

Step Two:

Go-to line number 97 (or there abouts), look for the following 2 lines of code:


$rnumA = rand(0,49);
$rnumB = rand(0,49);

Step Three:

To make the math question single digits, change the above 2 lines to:


$rnumA = rand(0,9);
$rnumB = rand(0,9);

Step Four:

Save config.php and upload to your webserver.

If you would prefer to remove the math question altogether and replace with some other question, follow these steps:

Step One:

Open config.php in your favorite text/script editor.

Step Two:

Go-to line number 102 (or there abouts), look for the following 2 lines of code:


$question = "$rnumA plus $rnumB?";
$answer = $rnumA+$rnumB;

Step Three:

Change the question and required answer to something like this:


$question = "What day comes after monday?";
$answer = "tuesday";

(You can change the question and answer to pretty much anything you like!)

Step Four:

Open process_form.php and goto line 118 (or there abouts), look for the following line of code:


if($ans_one === $ans_two) {

Change the above line to:


if(strtolower($ans_one) === strtolower($ans_two)) {

This change removes the case sensitive restriction!

Step Five:
Save config.php and process_form.php then upload them to your webserver.

I told you it was easy :)

Allow sender to specify subject line

Tuesday, August 28th, 2007

I recently had the following question from a FCF user:

QUESTION

Hello, I am using your contact form script and I’d like to know if it’s possible for the sender to add his own subject to the e-mail. If so, how would I go about adding that feature?

ANSWER

This could be achieved several ways, I’ll explain the simplest method here for clarity.

Step One:

Open form.php in your favorite text/script editor.

Step Two:

Go-to line number 36 or there abouts (with the line: required.add('answer_out', 'NUMERIC');)

Step Three:

Create 1 new lines above line number 36, and enter the following :

required.add('subject_line', 'NOT_EMPTY');

We are including validation for our new subject line field - this will prompt the user to include a subject line if they try to submit the form without it. At this stage we have only included JavaScript validation - later we will also include PHP validation.

Step Four:

Goto line 46 or there abouts (with the line <div class="r">)

Insert the following code ABOVE line 46:


<div class="r">
<label for="subject_line" class="req">Subject: <em>*</em></label>
<span class="f">
<input type="text" name="subject_line" size="40" id="subject_line" onBlur="trim('subject_line')">
</span>
</div>

Step Five:

Save form.php, we are done with that file now.

Step Six:

Open process_form.php in your favorite text/script editor.

Step Seven:

Go to line 89 or there abouts (with the line $reqobj->add("answer_out","NUMERIC");)

Insert the following code just below line 89:


$reqobj->add("subject_line","NOT_EMPTY");

Here we have included the PHP validation which makes sure the subject line exists.

Step Eight:

Go to line 159 or there abouts (with the line // create email headers )

Insert the following code just above line 159:


$ns = new clean;
$ns->comments($subject_line);
$email_subject = $ns->message;

The above code cleans up any HTML/Script which the user may have entered in the subject line.

Step Nine:

save process_form.php and upload both form.php and process_form.php to your webserver.

What the above script modification will do
With the above changes to your scripts, you can now allow the form users to enter their own subject line. The script will validate the subject line value, and if successful, you will receive your email message with the users subject line.

Include Users IP in Contact Form Message

Monday, August 27th, 2007

I recently had the following question from a FCF user:

QUESTION

I was wondering whether there was anyway of logging the IP address of the people who submit the forms? I occasionally get kids or jokers sending in daft (although technically relevant) things to my site and I’d like to keep a little list of people to be wary of! Thanks for any info.

ANSWER

I like nice easy questions like this one :)

Step One:

Open process_form.php in your favorite text/script editor.

Step Two:

Go-to line number 161 or there abouts (with the line: // create email headers)

Step Three:

Create 1 new lines above line number 160, and enter the following :

$mail_message .= "IP Address: ".$_SERVER['REMOTE_ADDR']."\n";

(note: if you copy/paste the above code, you may need to fix the double quote characters!)

Step Four:

Save the file and upload to your server (overwrite the original process_form.php file if it already exists)

What the above script modification will do
This slight change will allow you to see what IP Address the form user has. The IP Address will appear in your email (after all the other form field data).

Send form message to sender also

Wednesday, August 15th, 2007

I recently had the following question from a FCF user:

QUESTION

‘How can I send the information in the FCF to the person completing the form, as well as to myself?’

ANSWER

In order to have the email message (which the form generates) also sent to the form user, you need to make a simple change to ‘process_form.php. Follow the simple steps below.

Step One:

Open process_form.php in your favorite text/script editor.

Step Two:

Go-to line number 163 (with the line: // send the email)

Step Three:

Create 2 new lines under line number 163, and enter the following :

$email_message = “Thank you for contacting us, we have received the following message\n\n”.$email_message;
@mail($email_from, $email_subject, $email_message, $headers);

(note: if you copy/paste the above code, you may need to fix the double quote characters!)

Step Four:

Save the file and upload to your server (overwrite the original process_form.php file if it already exists)

What the above script modification will do

With the above modification in place, your form will now send a message to the form user as well as you. However the form users message will start with the text ‘Thank you for contacting us, we have received the following message’ (and your message will appear under this).

If you send me your modification requirements, I will hopefully base a new post on your question!

Include senders name in subject line

Wednesday, August 15th, 2007

I recently had the following question from a FCF user:

QUESTION

‘I am wanting to slightly modify the subject line with the sender’s name included. Can you please let me know how this can be done?’

ANSWER

This requires very slight modification to one of the scripts (process_form.php).

Step One:

Open process_form.php in your favorite text/script editor.

Step Two:

Go-to line number 159 (with the line: // create email headers)

Step Three:

Create a new line under line number 159, and enter the following:

$email_subject .= " ".$_POST['fullname'];

Step Four:

Save the file and upload to your server (overwrite the original process_form.php file if it already exists)

What the above script modification will do

The example given above will append the form senders ‘fullname’ to the end of the subject line. Keep in mind that you already can configure the subject line in config.php (around line 34).

If you want to make the subject line have the senders name inside the subject line (i.e. not at the end of the subject line), then change the above code in Step Three to something like:

$email_subject = $_POST['fullname']." sent you a message";

The above will make the subject like look like:

Trevor McDonald sent you a message

(if the senders name is Trever McDonald)

This post will hopefully give you an idea of how to make some simple changes to your contact us form. This is based on FCF Version 3 Beta 2!

If you want to know how to do something with FCF - drop me a message!

New spam prevention blog

Tuesday, August 14th, 2007

After more than 1 year of considering using a blog system for ‘Free Contact Form‘ it’s finally here. I have decided to use this to post details on how to configure your spam prevention forms to fit your own needs (I have a list of commonly requested customizations). I also intend to occasionally write up general spam prevention articles.

Is there something you would like FCF to do which is does not currently offer? please give your suggestions?