xd hanieldarrison
Platform Strategist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
500 XP
We are going to create Contact Form with Captcha Confirmation using PDO in PHP. These simple tutorial, you can download for free. I will teach you in step by step on how to create a contact form with captcha confirmation using PDO in PHP. Also, you can learn how to generate a random code and you can use this to protect your page from random spammers. You can use this also as a type of a simple test that the response is generated by a human being and it's a very common on other websites before submitting the information in the form field.
You will learn:
Creating Markup and Captcha Random Code
This simple source code, we are going to create our contact form where the user can type their message, full name, and email. Also, we construct the captcha random code for the confirmation before they submit their message.
PHP Source Code in PDO
This is our contact query where they can save all the data from the users. Save it as "contact_query.php".
Output
This is the form where you can enter your full name, email, message and the captcha confirmation to contact any certain websites.
The user enter their information and message to contact any websites.
This is the result after enter all information, message, and the captcha confirmation as you can see in the image below.
And, that's it. This is the steps on how to create simple Contact Form with Captcha Confirmation using PDO in PHP.
Kindly click the "Download Code" button below for full source code. Thank you very much.
Hope that this tutorial will help you a lot.
If you are interested in programming, we have an example of programs that may help you even just in small ways.
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much. Enjoy coding.
Download
You will learn:
- The user learns to generate a random code.
- The user learns the basics of CSS styling.
- The user learns to create contact form using HTML.
- The user learns to create stylish contact form using CSS.
Creating Markup and Captcha Random Code
This simple source code, we are going to create our contact form where the user can type their message, full name, and email. Also, we construct the captcha random code for the confirmation before they submit their message.
- <form
class
=
"form-horizontal"
method
=
"POST"
action
=
"contact_query.php"
>
- <p
class
=
"full_name"
>
- <input
type
=
"text"
name
=
"full_name"
id
=
"full_name"
placeholder=
""
autofocus=
"autofocus"
required/
>
- <label
for
=
"full_name"
>
Your Name</
label
>
- </
p
>
- <p
class
=
"email"
>
- <input
type
=
"email"
name
=
"email"
id
=
"email"
placeholder=
""
required/
>
- <label
for
=
"email"
>
Your Email Address</
label
>
- </
p
>
- <p
class
=
"message"
>
- <textarea
name
=
"message"
placeholder=
""
required></
textarea
>
- <label
for
=
"message"
>
Your Message</
label
>
- </
p
>
- <div
class
=
"control-group"
style
=
"float:left; margin-left:-185px;"
>
- <div
class
=
"controls"
>
- <img
src
=
"generatecaptcha.php?rand=<?php echo rand(); ?>
" name="captcha_img" id='image_captcha' >
- <a
href
=
'javascript: refreshing_Captcha();'
><i
class
=
"icon-refresh icon-large"
></
i
></
a
>
- <script
language
=
'JavaScript'
type
=
'text/javascript'
>
- function refreshing_Captcha()
- {
- var img = document.images['image_captcha'];
- img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
- }
- </
script
>
- </
div
>
- </
div
>
- <br
/
>
- <br
/
>
- <br
/
>
- <div
class
=
"control-group"
style
=
"margin-left:-181px;"
>
- <div
class
=
"controls"
>
- <input
id
=
"code"
name
=
"code_confirmation"
type
=
"text"
placeholder=
"Enter the Code Above"
required></
td
>
- </
div
>
- </
div
>
- <div
class
=
"control-group"
style
=
"margin-left:-181px;"
>
- <div
class
=
"controls"
>
- <button
type
=
"submit"
name
=
"send_message"
class
=
"btn btn-primary"
><i
class
=
"icon-ok icon-large"
></
i
>
Submit</
button
>
- </
div
>
- </
div
>
- </
form
>
PHP Source Code in PDO
This is our contact query where they can save all the data from the users. Save it as "contact_query.php".
- <?php
- session_start
(
)
;
- include
(
'db.php'
)
;
- if
(
isset
(
$_POST
[
'send_message'
]
)
)
{
- $full_name
=
$_POST
[
'full_name'
]
;
- $email
=
$_POST
[
'email'
]
;
- $message
=
$_POST
[
'message'
]
;
- $code_confirmation
=
$_POST
[
'code_confirmation'
]
;
- if
(
strcmp
(
$_SESSION
[
'code_confirmation'
]
,
$_POST
[
'code_confirmation'
]
)
!=
0
)
{
- echo
"<script>alert('The captcha code does not match!!'); window.location='index.php'</script>"
;
- echo
"<script>javascript:self-history.back() </script>;"
;
- }
else
{
- $conn
->
setAttribute
(
PDO::
ATTR_ERRMODE
,
PDO::
ERRMODE_EXCEPTION
)
;
- $insert_query
=
"INSERT INTO tbl_contact (full_name, email, message, code_confirmation)
- VALUES (?, ?, ?, ?)"
;
- $insert
=
$conn
->
prepare
(
$insert_query
)
;
- $insert
->
execute
(
array
(
$full_name
,
$email
,
$message
,
$code_confirmation
)
)
;
- echo
"<script>alert('Successfully send your message!'); window.location='index.php'</script>"
;
- }
- }
- ?>
Output
This is the form where you can enter your full name, email, message and the captcha confirmation to contact any certain websites.

The user enter their information and message to contact any websites.

This is the result after enter all information, message, and the captcha confirmation as you can see in the image below.

And, that's it. This is the steps on how to create simple Contact Form with Captcha Confirmation using PDO in PHP.
Kindly click the "Download Code" button below for full source code. Thank you very much.
Hope that this tutorial will help you a lot.
If you are interested in programming, we have an example of programs that may help you even just in small ways.
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much. Enjoy coding.
Download
You must upgrade your account or reply in the thread to view hidden text.