Jump to content

Help with Contact Form code


Recommended Posts

This contact form code does not send the Form info, and does not show 'completed' or 'not completed' message, can you help me add what's needed, please?

 

<form action="../index.php" method="post" name="contact_us" onSubmit="return capCheck(this);">
<tr>
<td>
<input id="name" name="name" value="NAME" onfocus="if (this.value=='NAME') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Name')" onblur="clickrecall(this,'Enter Name1')" />
</td>
<td>
<input id="name" name="email" value="EMAIL" onfocus="if (this.value=='EMAIL') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Email')" onblur="clickrecall(this,'Enter Email1')" />
</td>
<td>
<input id="name" name="subject" value="SUBJECT" onfocus="if (this.value=='SUBJECT') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Subject')" onblur="clickrecall(this,'Enter Subject1')" />
</td>
</tr>
<tr>
<td colspan="3"><input id="textbox1" name="comments" value="COMMENTS" onfocus="if (this.value=='COMMENTS') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Comments')" onblur="clickrecall(this,'Enter Comments1')" />
</td>
</tr>
<tr>
<td>
<input id="captext" type="text" name="captext" style="maxlength="6" value="" /></td>
<td><img src="../includes/captcha.php" border="0" id="verification_image" /></a><center><a onclick="refresh_security_image(); return false;" style="cursor:pointer;"><u>Refresh Image</u></a><center>
</td>
<td><input type="hidden" name="submitted" value="1" /><input class="my-input" type="submit" value="SEND MESSAGE">
</td>
</tr>
</form>
<!--<script type="text/javascript">
if($_POST['submitted'] == "1"){

$your_email = "support@.....com";
$from = "From: contact-form@.....com". "\r\n"; 
$user_email = $_POST['email'];
$user_name = $_POST['name'];
$subject = $_POST['subject'];
$email_body = $_POST['comments'];

if($user_email == "" or $user_name == "" or $subject == "" or $email_body == ""){
$error = "Please Complete All Required* Fields";
}else{

$message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name  \n\n\n Users Message : \n\n$email_body";

//SEND THE EMAIL -

mail($your_email, $subject, $message, $from);

$result = "Your Message Has Been Sent. Thank You";

}
}
$message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body";
//End Contact Us -
</script>-->
 
 
Link to post
Share on other sites

Yes, sorry I got confused. So, I would need to put this in it's own php file? If so, how would the Form connect with that file, or visa versa

Thanks  

if($_POST['submitted'] == "1"){

$your_email = "support@.....com";
$from = "From: contact-form@.....com". "\r\n"; 
$user_email = $_POST['email'];
$user_name = $_POST['name'];
$subject = $_POST['subject'];
$email_body = $_POST['comments'];

if($user_email == "" or $user_name == "" or $subject == "" or $email_body == ""){
$error = "Please Complete All Required* Fields";
}else{

$message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name  \n\n\n Users Message : \n\n$email_body";

//SEND THE EMAIL -

mail($your_email, $subject, $message, $from);

$result = "Your Message Has Been Sent. Thank You";

}
}
$message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body";
//End Contact Us -
Link to post
Share on other sites

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// process form
}
?>
<!DOCTYPE html>
<html>

<head>
<title></title>
</head>

<body>
<form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post">
<!-- FORM HERE -->
</form>
</body>
</html>
Link to post
Share on other sites

Thank you for your reply.

 

So, this part would come after // process form ?

if($_POST['submitted'] == "1"){

$your_email = "support@.....com";
$from = "From: contact-form@.....com". "\r\n"; 
$user_email = $_POST['email'];
$user_name = $_POST['name'];
$subject = $_POST['subject'];
$email_body = $_POST['comments'];

if($user_email == "" or $user_name == "" or $subject == "" or $email_body == ""){
$error = "Please Complete All Required* Fields";
}else{

$message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name  \n\n\n Users Message : \n\n$email_body";

//SEND THE EMAIL -

mail($your_email, $subject, $message, $from);

$result = "Your Message Has Been Sent. Thank You";

}
}
$message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body";
//End Contact Us -
Link to post
Share on other sites

benanamen has shown you perfectly what to do:

 

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    // process form
}
?>
<!DOCTYPE html>
<html>

<head>
  <title></title>
</head>

<body>
<form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post">
<!-- FORM HERE -->
</form>
</body>
</html>

 

try this

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    echo 'well done you have submitted the form';
}
else
{
?>
<form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post">
<input type="text" name="name" />
<input type="submit" name="submit" value="submit"/>
</form>
<?php
}
?>
</body>
</html>
Edited by Destramic
Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.