FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Simple Html Php Form not working
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Simple Html Php Form not working [message #178830] Fri, 10 August 2012 19:49 Go to previous message
bpascal123 is currently offline  bpascal123
Messages: 3
Registered: August 2012
Karma:
Junior Member
Hi,

I'm new to Php, I understand basic coding things related to variable, loops, functions... more client side. I would like a contact or comments form on my website http://multiskillz.tekcities.com

The page where the form is is there http://multiskillz.tekcities.com/index99_comments.php or link comment on the left window.

I have used the php code from this web site http://www.freecontactform.com/email_form.php

I made a few changes since I don't want exactly the same thing:

Below is the html (index99_comments.html)

<div id="gate_A_resize3_comments"><p id="blackboard"></p>

<form method="post" name="contact_form" action="contact-form-handler.php">
<br><br><br><br>
Your Name:
<input type="text" name="name">
<br><br><br><br>
Email Address:
<input type="text" name="email">
<br><br><br>
Message:
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
<input type="submit" value="Submit"> <a href="email_form.php"></a>
</form>
</div>


And below the php related php code (email_form.php)


<?php

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

//EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "pascal(dot)baro(at)hotmail(dot)com";
$email_subject = "Website";

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

if (!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['comments'])) {
died('We are sorry, but a field is missing.');
}
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$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 is not valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp, $name)) {
$error_message .= 'The name does not seem valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The comments does not seem valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
$bad = array("content-type", "bcc:", "to:", "cc:", "href");
return str_replace($bad, "",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";

//create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n".
'X-Mailer: PHP/' .phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->

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

<?php
}
?>


I understand I have to change a few settings on the localhost server for this work locally (I'm using Windows 7 and Xamp). As I want to get quickly to the point, I'm testing it directly online on http://multiskillz.tekcities.com/index99_comments.php and it just keeps failing.

Do I have to change settings on the server as well (batcave or tekcities)?
Or is it something about the code?

Thanks if you can provide any clue or answer.

Pascal
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Create hierarchical tree structure for categories in joomla
Next Topic: Free service to allow large file upload in PHP forms
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 00:27:18 GMT 2024

Total time taken to generate the page: 0.05032 seconds