...

View Full Version : Getting no response from PHP form



Alex Bennett
11-08-2010, 08:25 PM
Hi all...

Don't know an awful lot about PHP, hence on here, so may be missing something pretty obvious.

I'm using this PHP form that I got from an open source site on a website, but after testing it several times, I'm getting no response.

Could this be a problem on the server side, or is there something wrong with the code? Since it looks fine after upload, I presume the server supports PHP ok.

Here's the code with some HTML implemented to match it with the rest of the site:




<?php
$comments_textarea_1 = "<text";
$comments_textarea_2 = 'area name="comments" cols="40" rows="6">';
$end_textarea_1 = "</text";
$end_textarea_2 = "area>";
if (!function_exists('str_split')) {
function str_split($string, $split_length = 1) {
return explode("\r\n", chunk_split($string, $split_length));
}
}

function generateDropDown($values,$value_selected) {
$value_array = explode(',',$values);
$i = 0;
while ($value_array[$i] != '') {
if ($value_array[$i] == $value_selected) {
$selected = ' selected ';
} else {
$selected = '';
}
$options .= '<option value="' . $value_array[$i] . '" ' . $selected . '>' . $value_array[$i] . '</option>';
$i++;
}
return $options;
}

function checkValidChars($string,$valid_chars) {
$string_array = str_split($string);
$valid_chars_array = str_split($valid_chars);
$i = 0;
while ($string_array[$i] != '') {
if (!in_array($string_array[$i],$valid_chars_array)) {
return false;
}
$i++;
}
return true;
}

function getResultDiv($value,$type='error') {
// Formats successful or error results whether they are in an array or a snippet.
if ($type == 'success') {
$class = 'success-div';
} elseif ($type == 'test') {
$class = 'test-div';
} else {
$class = 'error-div';
}
if (is_array($value)) {
for ($i = 0; $value[$i] != ''; $i++) {
$result_div .= '<li>' . $value[$i] . '</li>';
}
if ($result_div != '') {
$result_div = '<div class="' . $class . '"><ul>' . $result_div . '</ul></div>';
}
} else {
if ($value != '') {
$result_div = '<div class="' . $class . '">' . $value . '</div>';
}
}
return $result_div;
}

function getValidation($add_edit,$name,$msg,$type,$value='') {
global $edit_action;
global $add_action;
global $error_div;
global $_POST;
global $_GET;
if ($_POST['action'] == "submit_form") {
$do = 1;
}
// No value
if ($type == 'novalue') {
if ($do == 1) {
if (strlen($_POST[$name]) < '1') {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value == ""';
return jsCheck($js_clause,$msg,$name);
}

// Number is less than
if ($type == 'less_than') {
if ($do == 1) {
if ($_POST[$name] < $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value < ' . $value;
return jsCheck($js_clause,$msg,$name);
}

// Number is greater than
if ($type == 'greater_than') {
if ($do == 1) {
if ($_POST[$name] > $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value > ' . $value;
return jsCheck($js_clause,$msg,$name);
}

// Value equals
if ($type == 'equals') {
if ($do == 1) {
if ($_POST[$name] == $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value == ' . $value;
return jsCheck($js_clause,$msg,$name);
}

// Less Than String Length
if ($type == 'strlen_less') {
if ($do == 1) {
if (strlen($_POST[$name]) < $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value.length < ' . $value;
return jsCheck($js_clause,$msg,$name);
}

// String Length
if ($type == 'strlen') {
if ($do == 1) {
if (strlen($_POST[$name]) != $value) {
$error_div .= getResultDiv($msg);
}
}
$js_clause = 'form.' . $name . '.value.length != ' . $value;
return jsCheck($js_clause,$msg,$name);
}

// Zip Code
if ($type == 'zip') {
$valid_chars = "0123456789";
if ($do == 1) {
if (strlen($_POST[$name]) != 5) {
$error_div .= getResultDiv('Please enter 5 digits for the zip code');
} elseif (!checkValidChars($_POST[$name],$valid_chars)) {
$error_div .= getResultDiv('Please enter only digits for the zip code');
}
}
$js_clause_1 = 'form.' . $name . '.value.length != 5';
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';
return
jsCheck($js_clause_1,'Please enter 5 numbers for the zip code',$name) .
jsCheck($js_clause_2,'Please enter only numbers in the zip code',$name);
}

// Price
if ($type == 'price') {
$valid_chars = "0123456789.,";

if ($do == 1) {
$post_value = str_replace(',','',$_POST[$name]);
if (!checkValidChars($post_value,$valid_chars)) {
$error_div .= getResultDiv('Please enter only a number for ' . $msg);
} elseif (strlen($post_value) > $value) {
$error_div .= getResultDiv('Please enter a smaller value for ' . $msg);
}
}
$js_clause_1 = 'form.' . $name . '.value.length > ' . $value;
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';

return
jsCheck($js_clause_1,'Please enter no more than ' . $value . ' characters for ' . $msg,$name) .
jsCheck($js_clause_2,'Please enter only numbers for ' . $msg,$name);
}

// Number
if ($type == 'number') {
$valid_chars = "0123456789";
if ($do == 1) {
$post_value = str_replace(',','',$_POST[$name]);
if (!checkValidChars($post_value,$valid_chars)) {
$error_div .= getResultDiv('Please enter only a number for ' . $msg);
} elseif (strlen($post_value) > $value) {
$error_div .= getResultDiv('Please enter a smaller value for ' . $msg);
}
}
$js_clause_1 = 'form.' . $name . '.value.length > ' . $value;
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';

return
jsCheck($js_clause_1,'Please enter no more than ' . $value . ' numbers for ' . $msg,$name) .
jsCheck($js_clause_2,'Please enter only numbers for ' . $msg,$name);
}

// Phone Number
if ($type == 'phone') {
$valid_chars = "0123456789-() ";
$value = 7;
if ($do == 1) {
if (!checkValidChars($_POST[$name],$valid_chars)) {
$error_div .= getResultDiv('Please enter only a phone number for ' . $msg);
} elseif (strlen($post_value) > $value) {
$error_div .= getResultDiv('Please enter a smaller value for ' . $msg);
}
}
$js_clause_1 = 'form.' . $name . '.value.length < ' . $value;
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';

return
jsCheck($js_clause_1,'Please enter no more than ' . $value . ' numbers for the phone number',$name) .
jsCheck($js_clause_2,'Please enter a valid phone number',$name);
}


// Password
if ($type == 'password') {
$valid_chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ($do == 1) {
if (!checkValidChars($_POST[$name],$valid_chars)) {
$error_div .= getResultDiv('Please enter only alpha-numeric values for ' . $msg);
} elseif (strlen($_POST[$name]) < $value || $_POST[$name] == '') {
$error_div .= getResultDiv($msg . ' must be at least 6 characters long');
}
}
$js_clause_1 = 'form.' . $name . '.value.length < ' . $value . ' && ' . ' form.' . $name . '.value.length > 0';
$js_clause_2 = '!ValidChars(form.' . $name . '.value,"' . $valid_chars . '")';

return
jsCheck($js_clause_1,$msg . ' must be at least 6 characters long',$name) .
jsCheck($js_clause_2,'Please enter only alpha-numeric values for ' . $msg,$name);
}

// Duplicate
if ($type == 'duplicate') {
if ($do == 1) {
$value_array = explode(':',$value);
$table = $value_array[0];
$column = $value_array[1];
$content = $_POST[$name];
}
}

}

function jsCheck($clause,$msg,$name) {
return '
if (' . $clause . ') {
alert( "' . $msg . '" );
form.' . $name . '.focus();
return false;
}
';
}

$subject_options = generateDropDown("",$_POST['subject']);

$email['to'] = "my_email";
$email['subject_prefix'] = "Website query";


if ($_POST['action'] == 'submit_form') {

if (strlen($_POST['fullname']) < 1) {
$error_div .= getResultDiv('Please enter a value for your name');
}
if (strlen($_POST['email']) < 1) {
$error_div .= getResultDiv('Please enter a value for your email address');
}
if (strlen($_POST['comments']) < 10) {
$error_div .= getResultDiv('Please enter 10 or more characters for the comments');
}
$result_div .= $error_div;
if ($error_div == '') {
if (strlen($_POST["subject"] ) > 1) {
$message .= "SUBJECT: " . $_POST["subject"] . "\n";
}
if (strlen($_POST["fullname"]) > 1) {
$message .= "FROM: " . $_POST["fullname"] . "\n";
}
if (strlen($_POST["email"]) > 1) {
$message .= "EMAIL: " . $_POST["email"] . "\n";
}
if (strlen($_POST["phone"] ) > 1) {
$message .= "PHONE: " . $_POST["phone"] . "\n";
}
if (strlen($_POST["company"] ) > 1) {
$message .= "COMPANY: " . $_POST["company"] . "\n";
}
if (strlen($_POST["address"] ) > 1) {
$message .= "Address: " . $_POST["address"] . " " . $_POST["address_2"] . " " . $_POST["city"] . ", " . $_POST["state"] . " " . $_POST["zip"] . "\n";
}
if (strlen($_POST["comments"] ) > 1) {
$message .= "COMMENTS:\n" . $_POST["comments"] . "\n\n";
}
$message = "Below is the information submitted to your online Contact form on " . date('F j, Y') . " at " . date('j:i a') . ":\n\n" . $message;

if (mail($email['to'],$email['subject_prefix'] . $_POST['subject'], $message, "From: " . $_POST['email'])) {
header("Location: results.html");
}
} else {
$form = $_POST;
}
}
?>
<html>
<head>
<style>
.required {
font-weight:bold;
color:red;
}

.error-div {
border:1px solid #FF0000;
background-color:#FFDEDE;
padding:10px;
margin-bottom:5px;
color:#CC0000;
}

.success-div {
border:1px solid #09BD00;
background-color:#EEFFED;
padding:10px;
margin-bottom:5px;
color:#006600;
}
</style>
<script language="JavaScript" type="text/javascript">


var IE = (document.all) ? 1 : 0;
var DOM = 0;
if (parseInt(navigator.appVersion) >=5) {DOM=1};

function txtShow( cId, txt2show ) {
// Detect Browser
if (DOM) {
var viewer = document.getElementById(cId);
viewer.innerHTML=txt2show;
} else if(IE) {
document.all[cId].innerHTML=txt2show;
}
}//txtshow

function getTxt( cId ) {
var output = "";
// Detect Browser
if (DOM) {
var viewer = document.getElementById(cId);
output = viewer.value;
}
else if(IE) {
output = document.all[cId].value;
}
return output;
}//getTxt

function countChars(cBoxName, cTxtName, maxKeys) {
var str = new String(getTxt(cBoxName));
var len = str.length;
var showstr = '<span class="alert-pos">' + len + ' characters of ' + maxKeys + ' entered</span>';
if (len > maxKeys) showstr = '<span class="alert">' + len + ' characters of ' + maxKeys + ' entered</span><br /><span class="alert">Too many characters, please edit content</span>';
txtShow( cTxtName, showstr );
}

function ValidChars(sText,ValidChars) {
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++) {
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
}
}
return IsNumber;
}

function checkform (form) {

if (form.fullname.value == "") {
alert( "Please enter your full name" );
form.fullname.focus();
return false;
}

if (form.email.value.length < 5) {
alert( "Please enter your email" );
form.email.focus();
return false;
}

if (form.comments.value.length < 10) {
alert( "Please enter 10 or more characters for the comments" );
form.comments.focus();
return false;
}

}
</script>
<title>Contact Us</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cafe and art gallery | Hinckley | Leicestershire</title>

<!-- verification for google -->
<meta name="google-site-verification" content="7eeW046ryBQw0XZWP8QbI3Yzpd04UZ8SdNnADtUtu3o" />

<link href="styles-ci.css" rel="stylesheet" type="text/css" />

</head>
<body>

<div id="wrapper"><!--wrapper div start-->

<div id="banner"><!--banner div start-->
<div class="bannerlogo"><img src="images/logos/logo-no-background-withill.png" /></div>
<div class="bannertext">For coffee and inspiration</div>
</div><!--banner div end-->

<div id="toplinkstable"><!-- start of toplinks -->
<table><tr>
<td><a class="toplinks" href="menus.html" title="Menus"><span>menus</span></a></td>
<td><a class="toplinks" href="gallery.html" title="Take a tour of Cafe Impressions"><span>Tour of the caf&eacute;</span></a></td>
<td><a class="toplinks" href="events.html" title="Upcoming events"><span>Upcoming events</span></a></td>
<td><a class="toplinks" href="find-us.html" title="Where are we?"><span>Where are we?</span></a></td>
<td><a class="toplinks" href="contact-us.html" title="Contact us"><span>Contact us</span></a></td>
</tr></table>
</div><!-- end of toplinks table-->

<div id="sidenav"><!-- side navigation div start-->
<div id="breadcrumb"><!-- breadcrumb div start -->
<a href="index.html">Home</a>>Contact Us
</div><!-- breadcrumb div end -->
<ul class="navlist">
<li><a href="gallery.html">Tour of the caf&eacute;</a></li>
<li><a href="atkins-building.html">The Atkins Building</a></li>
<li><a href="shop.html">Shop</a></li>
<li><a href="whats-around.html">What's in the area</a></li>
<li><a href="play-for-us.html">Play for Cafe Impressions</a></li>
<li><a href="opening-hours.html">Opening hours</a></li>
<li><a href="contact-us.html">Contact us</a></li>
</ul>

<div style="width:113px; margin-left:auto; margin-right:auto; margin-top:30px; margin-bottom:20px;"><img src="images/logos/logo_rijo.gif" /></div>

</div><!-- side navigation div end-->


<div id="maincontent"><!-- start of main content -->


<h2>Contact us</h2>
<p>For information on any of the items listed on this site, please contact:</p>

<p>Paul Bennett on 07939 532523</p>
<p>Or Alexandra Richards on 07854 979765</p>

<p>Alternatively email cafeimpressions@gmail.com</p>

<p>Cafe Impressions | Atkins Building | Lower Bond Street | Hinckley | Leicestershire | LE10 1QU</p>

<div class="formdiv">
<?php echo $result_div; ?>
<h5>Enquiry form</h5>
<form action="contact.php" onSubmit="return checkform(this);" method="post">
<input type="hidden" name="action" value="submit_form" />
<table>
<tr>
<td><span class="required">*</span>Full Name: </td>
<td><input type="text" name="fullname" value="<?php echo $form['fullname']; ?>" size="40" /></td>
</tr>
<tr>
<td><span class="required">*</span>E-mail: </td>
<td><input type="text" name="email" size="40" value="<?php echo $form['email']; ?>" /></td>
</tr>
<tr>
<td>Company: </td>
<td><input type="text" name="company" size="40" value="<?php echo $form['company']; ?>" /></td>
</tr>
<tr>
<td><span class="required">*</span>Comments: </td>
<td><?php echo $comments_textarea_1 . $comments_textarea_2; ?><?php echo $form['comments']; ?><?php echo $end_textarea_1 . $end_textarea_2; ?></td>
</tr>
</table>
<input type="submit" value="Submit Contact Form" />
</form>
</div>

</div><!-- end of main content -->

<div id="footer"><!-- start of footer div -->
<p>&copy;Cafe Impressions | Atkins Building | Lower Bond Street | Hinckley | Leicestershire | LE10 1QU</p>
</div><!-- end of footer div -->

</div><!--wrapper div end-->

<div class="creditbox"><p class="credit">Site design by <a href="http://www.designjungle.co.uk/">Design Jungle</a>. <a href="http://www.impliedbydesign.com/1-articles/">Web Design Articles</a> and Free Tools by Implied By Design</a></p></div>

</body>
</html>



If needed, here's a link to the page I've uploaded and tested:

http://www.cafeimpressions.co.uk/contact.php

Thanks for looking! Alex

mlseim
11-08-2010, 08:51 PM
Look at these two lines:

$email['to'] = "my_email";
$email['subject_prefix'] = "Website query";

Did you put your real email address in place of "my_email" ?
That's where the form gets sent to.

The other line is what the subject line will be for the email you get.


.

Alex Bennett
11-09-2010, 08:57 AM
Hi, yes I did put my own email in here - wasn't sure if it was standard practice to substitute my own email on public forums...

I don't get many emails to the address I've used, so it wouldn't be hard to miss one called 'website query'.

I wasn't sure if the problem could be to do with the server I'm using, but am I right in thinking if the page displays okay, it must support PHP?

Thanks

low tech
11-09-2010, 09:53 AM
Hi

I'm not a pro coder

but thought you might like to know

I just uploaded your page "as is" to my site and put in my email address --- opened the page -------filled in the form and I got the mail

so the mailer is working

not sure if that helps at all

LT

I go this in my mailbox:

Below is the information submitted to your online Contact form on November 9, 2010 at 9:45 am:

FROM: peter pan
EMAIL: what@what.com
COMMENTS:
what do you want me to say

Alex Bennett
11-09-2010, 10:48 AM
Thanks everyone,

Yep, I realise now the host server I'm using isn't configured!

It does have a Pear package though, that I've been able to install.

Does anyone therefore know the best way to modify this script to include the pear/smtp settings for mail on this server? I found this code on the web:




<?php
include("Mail.php");
/* mail setup recipients, subject etc */
$recipients = "feedback@yourdot.com";
$headers["From"] = "user@somewhere.com";
$headers["To"] = "feedback@yourdot.com";
$headers["Subject"] = "User feedback";
$mailmsg = "Hello, This is a test.";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "smtp.mycorp.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "smtpusername";
$smtpinfo["password"] = "smtpPassword";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
?>



I reckon if I include this into my script with the right amendments it should be good to go?
:)

myfayt
11-09-2010, 01:56 PM
Free hosting, and dirt cheap hosting often don't have PHP support or perl, etc. It's pretty much HTML, CSS, Javascript all the way. So it's worth that few bucks to get a better hosting site.

Rowsdower!
11-09-2010, 02:15 PM
I disagree re: free hosting not supporting PHP. Freehostia has a very ample PHP offering (it doesn't include cURL or fopen abilities, but otherwise it supports just about anything an up-and-coming PHP developer would want). No ads either!

They don't always have the very best "up time" or connection speed, but they are very good for the price ($0.00). They also allow FTP access, which is not always available with free hosts.

If you're shopping for a free host they are worth a look. I have a paid hosting account elsewhere and still maintain my freehostia account for examples to post here and for development purposes when I don't want to bloat my paid account.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum