/    Sign up×
Community /Pin to ProfileBookmark

html forms help please

how to create contact form in html

to post a comment
HTML

10 Comments(s)

Copy linkTweet thisAlerts:
@jedaisoulDec 10.2015 — Hello and welcome to the site. The simple answer to your query is RT(F)M, or "Read the Manual". There is plenty of documentation on the web describing the HTML <FORM>, <INPUT> and <SELECT> tags which form the basis of an input form, whatever its purpose. However, a full answer is somewhat more complex. Why? Because all that HTML does is take the input and pass it on to a server-side script for processing. That script will need to be written in PHP or another server language. Without the script, the form is useless. Also, you will often want to validate the user input before passing it on to the server. For that you will need to use JavaScript.
Copy linkTweet thisAlerts:
@md_raselDec 10.2015 — For creating contact form using html you need to create script with php which will drive your data from front view to you.
Copy linkTweet thisAlerts:
@kite123Dec 29.2015 — hey,I am providing you with the code try this

<form name="htmlform" method="post" action="html_form_send.php">

<table width="450px">

</tr>

<tr>

<td valign="top">

<label for="first_name">First Name *</label>

</td>

<td valign="top">

<input type="text" name="first_name" maxlength="50" size="30">

</td>

</tr>

<tr>

<td valign="top"">

<label for="last_name">Last Name *</label>

</td>

<td valign="top">

<input type="text" name="last_name" maxlength="50" size="30">

</td>

</tr>

<tr>

<td valign="top">

<label for="email">Email Address *
</label>

</td>

<td valign="top">

<input type="text" name="email" maxlength="80" size="30">

</td>

</tr>

<tr>

<td valign="top">

<label for="telephone">Telephone Number</label>

</td>

<td valign="top">

<input type="text" name="telephone" maxlength="30" size="30">

</td>

</tr>

<tr>

<td valign="top">

<label for="comments">Comments *</label>

</td>

<td valign="top">

<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>

</td>

</tr>

<tr>

<td colspan="2" style="text-align:center">

<input type="submit" value="Submit"> ( <a href="http://www.freecontactform.com/html_form.php">HTML Form</a> )

</td>

</tr>

</table>

</form>


--You also need to save PHP script. This is used to store form submissions and send an email to you.

<?php

if(isset($_POST['email'])) {

// CHANGE THE TWO LINES BELOW
$email_to = "[email protected]";

$email_subject = "website html form submissions";


function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {

$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$first_name)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}

if(!preg_match($string_exp,$last_name)) {

$error_message .= 'The Last Name you entered does not appear to be valid.<br />';

}

if(strlen($comments) < 2) {

$error_message .= 'The Comments you entered do not appear to be valid.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$email_message = "Form details below.nn";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($first_name)."n";
$email_message .= "Last Name: ".clean_string($last_name)."n";
$email_message .= "Email: ".clean_string($email_from)."n";
$email_message .= "Telephone: ".clean_string($telephone)."n";
$email_message .= "Comments: ".clean_string($comments)."n";



// create email headers

$headers = 'From: '.$email_from."rn".

'Reply-To: '.$email_from."rn" .

'X-Mailer: PHP/' . phpversion();

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

?>

<!-- place your own success html below -->

Thank you for contacting us. We will be in touch with you very soon.

<?php

}

die();

?>


--Rest you can change according to your needs,like size and your email id.
Copy linkTweet thisAlerts:
@w3webJan 09.2016 — Hi JaydenFox[COLOR=#3e3e3e],

[/COLOR]


Here is the HTML Contact form with code you need to insert into your contact page.


<form id="contact_form" action="#" method="POST" enctype="multipart/form-data">

<div class="row">

<label for="name">Your name:</label><br />

<input id="name" class="input" name="name" type="text" value="" size="30" /><br />

</div>

<div class="row">

<label for="email">Your email:</label><br />

<input id="email" class="input" name="email" type="text" value="" size="30" /><br />

</div>

<div class="row">

<label for="message">Your message:</label><br />

<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />

</div>

<input id="submit_button" type="submit" value="Send email" />

</form>
Copy linkTweet thisAlerts:
@davidwarner033Feb 04.2016 — I think it useful to you:

<form id="contact_form" action="#" method="POST" enctype="multipart/form-data">

<div class="row">

<label for="name">Your name:</label><br />

<input id="name" class="input" name="name" type="text" value="" size="30" /><br />

</div>

<div class="row">

<label for="email">Your email:</label><br />

<input id="email" class="input" name="email" type="text" value="" size="30" /><br />

</div>

<div class="row">

<label for="message">Your message:</label><br />

<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />

</div>

<input id="submit_button" type="submit" value="Send email" />

</form>

Download s
Copy linkTweet thisAlerts:
@cheapseoserviceFeb 09.2016 — Here is your HTML contact Form.

Here, I assume that you have 2 fields. One for Name and other for Contact No. And File name which contain PHP code is "contact.php" and placed under same directory where your this HTML file .

HTML (contact.html)

<form method = "post" action = "contact.php">
<input type = "text" name "name" placeholder = "Enter Name" /><br>
<input type = "number" name "contact" placeholder = "Enter Contact No." /><br>
<br>
<input type = "email" name "email" placeholder = "Enter Your Email" />

<input type = "submit" value = "Send"/>
</form>



PHP (contact.php)

Please note that here I use simple php mail() but I don not recommened it.

Here I use $_REQUEST in place of $_POST. Normaly $_REQUEST method used when you are not sure about $_GET and $_POST.

<?php
$to = "[email protected]";
$subject = "Subject";
$txt = "You have email from". $_REQUEST['name'] ." and his/ her Contact No. is ". $_REQUEST['contact'] ." .";
$headers = "From:". $_REQUEST['email'] ."rn" .

mail($to,$subject,$txt,$headers);
?>



For execute this. you must have server which can run PHP. like Apache With PHP installed.

You can not send mail from your localhost. (Without 3rd party libs.)
Copy linkTweet thisAlerts:
@3wCornerFeb 09.2016 — The form looks like this:

<form method="post" action="index.php">

<label>Name</label>
<input name="name" placeholder="Type Here">

<label>Email</label>
<input name="email" type="email" placeholder="Type Here">

<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>

<input id="submit" name="submit" type="submit" value="Submit">


</form>

But you need to write your php code index.php so that the message from the contact form will be sent to admin email of the website.

<?php

$name = $_POST['name'];

$email = $_
POST['email'];

$message = $_POST['message'];

$from = 'From: TangledDemo';

$to = '[email protected]';

$subject = 'Hello';

$human = $_
POST['human'];

$body = "From: $namen E-Mail: $emailn Message:n $message";

if ($_POST['submit'] && $human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}

?>
Copy linkTweet thisAlerts:
@saharaliFeb 10.2016 — But you need to write your php code index.php so that the message from the contact form will be sent to admin email of the website.
Copy linkTweet thisAlerts:
@brknnyMar 02.2016 — Here is the code

<form id="contact_form" action="#" method="POST" enctype="multipart/form-data">

<div class="row">

<label for="name">Your name:</label><br />

<input id="name" class="input" name="name" type="text" value="" size="30" /><br />

</div>

<div class="row">

<label for="email">Your email:</label><br />

<input id="email" class="input" name="email" type="text" value="" size="30" /><br />

</div>

<div class="row">

<label for="message">Your message:</label><br />

<textarea id="message" class="input" name="message" rows="7" cols="30"></textarea><br />

</div>

<input id="submit_button" type="submit" value="Send email" />

</form>

You just need to add php script to process it.PHP script verifies whether html code is working or not and it also displays erros in the code if any.
Copy linkTweet thisAlerts:
@3wCornerMar 08.2016 — Below is a complete example of contact form as stated at http://www.w3schools.com/php/php_form_complete.asp

Name: <input type="text" name="name" value="<?php echo $name;?>">

E-mail: <input type="text" name="email" value="<?php echo $email;?>">

Website: <input type="text" name="website" value="<?php echo $website;?>">

Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>

Gender:

<input type="radio" name="gender"

<?php if (isset($gender) && $gender=="female") echo "checked";?>

value="female">Female

<input type="radio" name="gender"

<?php if (isset($gender) && $gender=="male") echo "checked";?>

value="male">Male
[/QUOTE]
×

Success!

Help @JaydenFox spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...