...

View Full Version : 2 unique forms on 1 page



chevy_ls_6
04-11-2012, 08:53 PM
Ok, so I'm needing a basic "contact" form and a "services needed" form, on the same page...I can get them both to send/validate on separate pages, but I can't for the life of me get the forms to validate/send *separately*.

I ran across an archived post from here @ CodingFourms that mentioned adding the hidden input and "if ( $_POST['formID']..." statements, but I've got something wrong somewhere.


<?php

if ( $_POST['formID'] == 'contact') {

define("EMAIL", "contact@southlakeradiology.com");

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

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);


//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$message_text = $v->errorNumMessage();

//store the errors list in a variable
$errors = $v->displayErrors();

//get the individual error messages
$nameErr = $v->getError("name");
$emailErr = $v->getError("email");
$messageErr = $v->getError("message");
}//end error check
}// end isset
}

if ( $_POST['formID'] == 'services') {
define("EMAIL", "contact@southlakeradiology.com");

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

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$location = trim($_POST['location']);
$value1 = trim($_POST['value1']);
$value2 = trim($_POST['value2']);
$value3 = trim($_POST['value3']);
$value4 = trim($_POST['value4']);
$message = trim($_POST['message']);


//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($phone, "phone", 3, 75);
$v->validateStr($location, "location", 3, 75);
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Location: " . $location . "\n";
$emailMessage .= "Value1: " . $email . "\n";
$emailMessage .= "Value2: " . $email . "\n";
$emailMessage .= "Value3: " . $email . "\n";
$emailMessage .= "Value4: " . $email . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$message_text = $v->errorNumMessage();

//store the errors list in a variable
$errors = $v->displayErrors();

//get the individual error messages
$nameErr = $v->getError("name");
$emailErr = $v->getError("email");
$phoneErr = $v->getError("phone");
$locationErr = $v->getError("location");
$messageErr = $v->getError("message");
}//end error check
}// end isset
}
?>

<?php include 'header.php'; ?>
<!--content starts below here-->
********UNDER CONSTRUCTION********
<p class="contact"><span>Toll Free Numbers:</span>&nbsp;Office (866) 333-8443 or Fax (866) 316-0080
</p>
<p class="contact"><span>Questions and/or Comments:</span>
</p>

<div id="contact_form_wrap">
<span class="message"><?php echo $message_text; ?></span>
<?php echo $errors; ?>
<?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
<form id="contact_form" method="post" action="contact.php"><input type="hidden" name="formID"
value="contact">
<p><label>Name:<br />
<input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $nameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $emailErr ?></span></p>

<p><label>Message: <br />
<textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $messageErr ?></span></p>

<p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
</div>

<p class="contact"><span>Radiology Needs:</span>
</p>
<div id="contact_form_wrap">
<span class="message"><?php echo $message_text; ?></span>
<?php echo $errors; ?>
<?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
<form id="services_form" method="post" action="contact.php"><input type="hidden" name="formID"
value="services">
<p><label>Name:<br />
<input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $nameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $emailErr ?></span></p>

<p><label>Phone: <br />
<input type="text" name="phone" class="textfield" title="phone" value="<?php echo htmlentities($phone); ?>" />
</label><br /><span class="errors"><?php echo $phoneErr ?></span></p>

<p><label>Location For Requested Services: <br />
<input type="text" name="location" class="textfield" title="location" value="<?php echo htmlentities($location); ?>" />
</label><br /><span class="errors"><?php echo $locationErr ?></span></p>

<div class="clearfix">
<p>
<input name="service" value="<?php echo htmlentities($value1); ?>" type="checkbox" />
<span>Here is the first selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value2); ?>" type="checkbox" />
<span>Here is the second selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value3); ?>" type="checkbox" />
<span>Here is the third selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value4); ?>" type="checkbox" />
<span>Here is the fourth selection</span>
</p>
</div>

<p><label>Message: <br />
<textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $messageErr ?></span></p>

<p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
</div>
<!--content ends above here-->
<?php include 'footer.php'; ?>

mlseim
04-11-2012, 08:59 PM
There must be something named the same on both forms ...
where the script can't figure out which one you're validating.

I see you have different form id's ...
id="contact_form"
id="services_form"

But these are the same:
<div id="contact_form_wrap">

And these are the same:
name="formID"

I suspect the "formID" will be the culprit.


.

tangoforce
04-11-2012, 09:03 PM
Well get rid of if($_POST['submit']) in both form processing blocks and see what happens. Check the details in my signature for reasons why.

chevy_ls_6
04-11-2012, 09:38 PM
Well get rid of if($_POST['submit']) in both form processing blocks and see what happens. Check the details in my signature for reasons why.
Heck, I'm just trying to get it working in FireFox for now...I'll worry about IE later, lol!

I ran across a couple different techniques on the web, but when I implement them it seems to break the validation...the way it is now, either submit button validates *both* forms. Uggh...

felgall
04-11-2012, 10:02 PM
The way I would resolve this would be to put a hidden form field in each form with the same name ('formid' would do) but a different value.

You then test for the existence of that field in order to determine that there is a form that has been submitted and needs to be validated and examine the value of the field in order to determine which form to validate.

tangoforce
04-12-2012, 12:06 AM
Right, debug time:

At the top of the processing script:

print_r($_POST);

Report back with the results.

chevy_ls_6
04-12-2012, 01:17 AM
Right, debug time:

At the top of the processing script:

print_r($_POST);

Report back with the results.

When I hit submit on top (contact) form:
Array ( [formID] => contact [name] => [email] => [message] => [submit] => Submit )

When I hit submit on bottom (services) form:
Array ( [formID] => services [name] => [email] => [phone] => [location] => [message] => [submit] => Submit )

Page url so y'all can mess with it: http://southlakeradiology.com/contact.php

tangoforce
04-12-2012, 01:06 PM
Right I've got this nailed:



include('validate.class.php');
$v = new validate();

//Get list of all errors I presume? - including missing fields..
$errors = $v->displayErrors();


Then you have:


<p class="contact"><span>Questions and/or Comments:</span>
</p>

<div id="contact_form_wrap">
<span class="message"><?php echo $message_text; ?></span>
<?php echo $errors; ?>


and:


<p class="contact"><span>Radiology Needs:</span>
</p>
<div id="contact_form_wrap">
<span class="message"><?php echo $message_text; ?></span>
<?php echo $errors; ?>


You're generating error messages for one form that are then being used in one variable that is used in both forms to display error messages. That means you'll display the messages twice.

This is proven by submitting the second form where I am then told the following - for the contact form:


Name must be at least 3 characters long.
Please enter an Email Address
Phone must be at least 3 characters long.
Location must be at least 3 characters long.
Message must be at least 5 characters long.


Instead of using '$errors' in both fields, try '$contactErrors' and '$serviceErrors'.


Just to reaffirm, you are NOT seeing both procession blocks of code executing - you are simply duplicating the use of the error messages.

tangoforce
04-12-2012, 02:02 PM
The way I would resolve this would be to put a hidden form field in each form with the same name ('formid' would do) but a different value.

You then test for the existence of that field in order to determine that there is a form that has been submitted and needs to be validated and examine the value of the field in order to determine which form to validate.

Do you actually read opening posts before posting or do you just read the title? I only ask because if you'd read the post itself you'd have noticed that the op is already one step ahead of you.

chevy_ls_6
04-12-2012, 03:44 PM
Right I've got this nailed:
Instead of using '$errors' in both fields, try '$contactErrors' and '$serviceErrors'.
I'm tip-toeing into php here, but I assume I will then have to change the rest of the $errors in contact.php as well as the validating page (validate.class.php), basically 2 validating pages?

tangoforce
04-12-2012, 05:32 PM
I'm tip-toeing into php here, but I assume I will then have to change the rest of the $errors in contact.php as well as the validating page (validate.class.php), basically 2 validating pages?

In contact.php yes. In validate.class.php no.

I've amended your php code below:




<?php

if ( $_POST['formID'] == 'contact') {

define("EMAIL", "contact@southlakeradiology.com");

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

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);


//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$message_text = $v->errorNumMessage();

//store the errors list in a variable
//*****************CHANGED THIS!!!**************
$contactErrors = $v->displayErrors();

//get the individual error messages
$nameErr = $v->getError("name");
$emailErr = $v->getError("email");
$messageErr = $v->getError("message");
}//end error check
}// end isset
}

if ( $_POST['formID'] == 'services') {
define("EMAIL", "contact@southlakeradiology.com");

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

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$location = trim($_POST['location']);
$value1 = trim($_POST['value1']);
$value2 = trim($_POST['value2']);
$value3 = trim($_POST['value3']);
$value4 = trim($_POST['value4']);
$message = trim($_POST['message']);


//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($phone, "phone", 3, 75);
$v->validateStr($location, "location", 3, 75);
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Location: " . $location . "\n";
$emailMessage .= "Value1: " . $email . "\n";
$emailMessage .= "Value2: " . $email . "\n";
$emailMessage .= "Value3: " . $email . "\n";
$emailMessage .= "Value4: " . $email . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$message_text = $v->errorNumMessage();

//store the errors list in a variable
//*****************CHANGED THIS!!!**************
$serviceErrors = $v->displayErrors();

//get the individual error messages
$nameErr = $v->getError("name");
$emailErr = $v->getError("email");
$phoneErr = $v->getError("phone");
$locationErr = $v->getError("location");
$messageErr = $v->getError("message");
}//end error check
}// end isset
}
?>

<?php include 'header.php'; ?>
<!--content starts below here-->
********UNDER CONSTRUCTION********
<p class="contact"><span>Toll Free Numbers:</span>&nbsp;Office (866) 333-8443 or Fax (866) 316-0080
</p>
<p class="contact"><span>Questions and/or Comments:</span>
</p>

<div id="contact_form_wrap">
<span class="message"><?php echo $message_text; ?></span>
<?php echo $contactErrors; ?>
<?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
<form id="contact_form" method="post" action="contact.php"><input type="hidden" name="formID"
value="contact">
<p><label>Name:<br />
<input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $nameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $emailErr ?></span></p>

<p><label>Message: <br />
<textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $messageErr ?></span></p>

<p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
</div>

<p class="contact"><span>Radiology Needs:</span>
</p>
<div id="contact_form_wrap">
<span class="message"><?php echo $message_text; ?></span>
<?php echo $serviceErrors; ?>
<?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
<form id="services_form" method="post" action="contact.php"><input type="hidden" name="formID"
value="services">
<p><label>Name:<br />
<input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $nameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $emailErr ?></span></p>

<p><label>Phone: <br />
<input type="text" name="phone" class="textfield" title="phone" value="<?php echo htmlentities($phone); ?>" />
</label><br /><span class="errors"><?php echo $phoneErr ?></span></p>

<p><label>Location For Requested Services: <br />
<input type="text" name="location" class="textfield" title="location" value="<?php echo htmlentities($location); ?>" />
</label><br /><span class="errors"><?php echo $locationErr ?></span></p>

<div class="clearfix">
<p>
<input name="service" value="<?php echo htmlentities($value1); ?>" type="checkbox" />
<span>Here is the first selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value2); ?>" type="checkbox" />
<span>Here is the second selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value3); ?>" type="checkbox" />
<span>Here is the third selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value4); ?>" type="checkbox" />
<span>Here is the fourth selection</span>
</p>
</div>

<p><label>Message: <br />
<textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $messageErr ?></span></p>

<p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
</div>
<!--content ends above here-->
<?php include 'footer.php'; ?>

That *SHOULD* fix it but if not please let us know.

chevy_ls_6
04-12-2012, 06:46 PM
tango: I had tried simply changing those 2 variables already (contactError and servicesError), and it still acts the same...your block of code is currently running on that page (http://southlakeradiology.com/contact.php).

What's gonna be a p!sser is when the owner changes his mind and decides he wants the forms split across 2 pages, lol...:D

tangoforce
04-12-2012, 07:49 PM
tango: ... it still acts the same...

No it doesn't. In fact it's made a very big difference only you're not sharp eyed enough to have noticed it.

Look at the form again and click submit for each one. Notice how now you only get error messages above the Name box for the correct form? - Previously you had them above both Name boxes. This means my changes have worked but I hadn't realised you were also outputting errors under each box. Again thats the same cause - using the same variable names.

Revised code:


<?php

if ( $_POST['formID'] == 'contact') {

define("EMAIL", "contact@southlakeradiology.com");

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

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$message = trim($_POST['message']);


//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$contact_message_text = $v->errorNumMessage();

//store the errors list in a variable
//*****************CHANGED THIS!!!**************
$contactErrors = $v->displayErrors();

//get the individual error messages
$contact_nameErr = $v->getError("name");
$contact_emailErr = $v->getError("email");
$contact_messageErr = $v->getError("message");
}//end error check
}// end isset
}

if ( $_POST['formID'] == 'services') {
define("EMAIL", "contact@southlakeradiology.com");

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

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$location = trim($_POST['location']);
$value1 = trim($_POST['value1']);
$value2 = trim($_POST['value2']);
$value3 = trim($_POST['value3']);
$value4 = trim($_POST['value4']);
$message = trim($_POST['message']);


//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($phone, "phone", 3, 75);
$v->validateStr($location, "location", 3, 75);
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Location: " . $location . "\n";
$emailMessage .= "Value1: " . $email . "\n";
$emailMessage .= "Value2: " . $email . "\n";
$emailMessage .= "Value3: " . $email . "\n";
$emailMessage .= "Value4: " . $email . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$service_message_text = $v->errorNumMessage();

//store the errors list in a variable
//*****************CHANGED THIS!!!**************
$serviceErrors = $v->displayErrors();

//get the individual error messages
$service_nameErr = $v->getError("name");
$service_emailErr = $v->getError("email");
$service_phoneErr = $v->getError("phone");
$service_locationErr = $v->getError("location");
$service_messageErr = $v->getError("message");
}//end error check
}// end isset
}
?>

<?php include 'header.php'; ?>
<!--content starts below here-->
********UNDER CONSTRUCTION********
<p class="contact"><span>Toll Free Numbers:</span>&nbsp;Office (866) 333-8443 or Fax (866) 316-0080
</p>
<p class="contact"><span>Questions and/or Comments:</span>
</p>

<div id="contact_form_wrap">
<span class="message"><?php echo $contact_message_text; ?></span>
<?php echo $contactErrors; ?>
<?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
<form id="contact_form" method="post" action="contact.php"><input type="hidden" name="formID"
value="contact">
<p><label>Name:<br />
<input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $contact_nameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $contact_emailErr ?></span></p>

<p><label>Message: <br />
<textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $contact_messageErr ?></span></p>

<p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
</div>

<p class="contact"><span>Radiology Needs:</span>
</p>
<div id="contact_form_wrap">
<span class="message"><?php echo $service_message_text; ?></span>
<?php echo $serviceErrors; ?>
<?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
<form id="services_form" method="post" action="contact.php"><input type="hidden" name="formID"
value="services">
<p><label>Name:<br />
<input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $service_nameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $service_emailErr ?></span></p>

<p><label>Phone: <br />
<input type="text" name="phone" class="textfield" title="phone" value="<?php echo htmlentities($phone); ?>" />
</label><br /><span class="errors"><?php echo $service_phoneErr ?></span></p>

<p><label>Location For Requested Services: <br />
<input type="text" name="location" class="textfield" title="location" value="<?php echo htmlentities($location); ?>" />
</label><br /><span class="errors"><?php echo $service_locationErr ?></span></p>

<div class="clearfix">
<p>
<input name="service" value="<?php echo htmlentities($value1); ?>" type="checkbox" />
<span>Here is the first selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value2); ?>" type="checkbox" />
<span>Here is the second selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value3); ?>" type="checkbox" />
<span>Here is the third selection</span>
</p>
<p>
<input name="service" value="<?php echo htmlentities($value4); ?>" type="checkbox" />
<span>Here is the fourth selection</span>
</p>
</div>

<p><label>Message: <br />
<textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $service_messageErr ?></span></p>

<p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
</div>
<!--content ends above here-->
<?php include 'footer.php'; ?>


You should start to notice some differences now.




What's gonna be a p!sser is when the owner changes his mind and decides he wants the forms split across 2 pages, lol...:D

Not really, tell him to hire me as part of the gang :thumbsup:

chevy_ls_6
04-12-2012, 08:02 PM
No it doesn't. In fact it's made a very big difference only you're not sharp eyed enough to have noticed it.

Ha! I'd agree with that! :D



You should start to notice some differences now.

Not really, tell him to hire me as part of the gang :thumbsup:
Yep, that did the trick...and he'd be money/time ahead if he did hire you, lol!

BTW: I think I caught a mistake I had made in the original "services" code that has gotten repeated:

It was...

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Location: " . $location . "\n";
$emailMessage .= "Value1: " . $email . "\n";
$emailMessage .= "Value2: " . $email . "\n";
$emailMessage .= "Value3: " . $email . "\n";
$emailMessage .= "Value4: " . $email . "\n";
$emailMessage .= $message;


But should be...(if I'm not mistaken)


$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Location: " . $location . "\n";
$emailMessage .= "Value1: " . $value1 . "\n";
$emailMessage .= "Value2: " . $value2 . "\n";
$emailMessage .= "Value3: " . $value3 . "\n";
$emailMessage .= "Value4: " . $value4 . "\n";
$emailMessage .= $message;


And again, MANY THANKS to all those who helped me with this, especially you, tango! :thumbsup:

Now, I guess I need to work on that whole IE _post isset issue...!

tangoforce
04-12-2012, 08:41 PM
You can remove the isset($_POST) part from both clauses (along with the matching { and }). It's just not needed - you're already looking for your hidden fields.

No comment on the other thing regarding the code you've posted, I never looked at it as it wasn't part of the problem I was dealing with.

chevy_ls_6
04-16-2012, 06:02 PM
Anyone see anything glaringly *wrong* with the contact form code below? I'm still not getting any emails from the form (to/from normal emails work), and the server folks haven't replied in several days now. I get the "form sent" results, and it seems to be validating correctly. Here's a phpinfo page I threw up, btw: click (http://www.southlakeradiology.com/test.php)

And here's the form:

<?php
if ( $_POST['formID'] == 'service') {
define("EMAIL", "contact@southlakeradiology.com");

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$location = trim($_POST['location']);
$value1 = trim($_POST['value1']);
$value2 = trim($_POST['value2']);
$value3 = trim($_POST['value3']);
$value4 = trim($_POST['value4']);
$value5 = trim($_POST['value5']);
$value6 = trim($_POST['value6']);
$value7 = trim($_POST['value7']);
$value8 = trim($_POST['value8']);
$value9 = trim($_POST['value9']);
$value10 = trim($_POST['value10']);
$value11 = trim($_POST['value11']);
$value12 = trim($_POST['value12']);
$value13 = trim($_POST['value13']);
$value14 = trim($_POST['value14']);
$message = trim($_POST['message']);


//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($phone, "phone", 3, 75);
$v->validateStr($location, "location", 3, 75);
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Location: " . $location . "\n";
$emailMessage .= "Daytime Final Reads: " . $value1 . "\n";
$emailMessage .= "Overflow Coverage: " . $value2 . "\n";
$emailMessage .= "Tele-Locums: " . $value3 . "\n";
$emailMessage .= "On-site Coverage: " . $value4 . "\n";
$emailMessage .= "PET or PET/CT: " . $value5 . "\n";
$emailMessage .= "CT: " . $value6 . "\n";
$emailMessage .= "MR: " . $value7 . "\n";
$emailMessage .= "US: " . $value8 . "\n";
$emailMessage .= "US Echocardiogram: " . $value9 . "\n";
$emailMessage .= "NM: " . $value10 . "\n";
$emailMessage .= "XRAY: " . $value11 . "\n";
$emailMessage .= "Overread Service: " . $value12 . "\n";
$emailMessage .= "PACS ASP: " . $value13 . "\n";
$emailMessage .= "Radiology RFP: " . $value14 . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header);

//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$service_message_text = $v->errorNumMessage();

//store the errors list in a variable
//*****************CHANGED THIS!!!**************
$serviceErrors = $v->displayErrors();

//get the individual error messages
$service_nameErr = $v->getError("name");
$service_emailErr = $v->getError("email");
$service_phoneErr = $v->getError("phone");
$service_locationErr = $v->getError("location");
$service_messageErr = $v->getError("message");
}//end error check
}
?>

bestjobstore
04-16-2012, 06:35 PM
I am using $_REQUEST['FORM_NAME'] and it works. So what is the problem.




http://www.bestjobstore.com

chevy_ls_6
04-16-2012, 06:53 PM
The form [email] never shows up...

mlseim
04-16-2012, 07:59 PM
Chevy ... try this:


//use php's mail function to send the email
if(!mail($email_to, $subject ,$emailMessage ,$header)){
echo "mail did not send for some reason";
}

I'm thinking your script (CPU) is timing out before the mail function gets executed completely.
By putting the mail function into an "if" statement, it forces PHP to wait until it
gets a "true" or "false". If it's "false", you'll get the did not send message.
But if it's true, the function has completed, and the script moves on.

See if this is what's causing your issue (I'm just guessing here).

chevy_ls_6
04-16-2012, 10:11 PM
Ok, I'll try it...

Edit: I added the above, and upon sending I immediately got the "Your message has been sent" message as well as resolving to the "http://southlakeradiology.com/contact.php?sent=yes" url, just as before...seems like maybe it took it a split second longer to show up, but maybe just wishful thinking on my part, lol.

[BTW: I'm checking for messages with Outlook Express and a normal email from another account to the account address shows up immediately, so that parts working...but, for some reason, Horde/Squirrel mail on the hosting server won't let me login to check my mail on the server itself?]

chevy_ls_6
04-18-2012, 03:37 PM
Ok, chatted with a live representative on the server, submitted a form, and this is what the log spit out:

Apr 18 09:34:55 web17 sendmail[12588]: q3IEYti1012588: to=contact@southlakeradiology.com, ctladdr=retrumpe (1425/709), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30410, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (q3IEYt8n012589 Message accepted for delivery)

I don't own a secret decoder ring, but it says "sent" and "message accepted for deliver", which seem like good things...but...?

tangoforce
04-18-2012, 05:25 PM
Nothing else to say to that I'm afraid. If the message has been accepted then it's a problem with the server I'm afraid or the recipients spam filters.

chevy_ls_6
04-19-2012, 04:08 PM
Ok, I spent nearly all day in a chat with the server people with no resolve...they did have to do some maintenance on the mail server because it was messed up, but that still didn't fix it...finally they emailed me this morning and the account had been "blocked because of spam"...once they took care of that it worked.

Anyway, the form is emailing now finally, but it's not returning any of the check box info...?


<?php
if ( $_POST['formID'] == 'service') {
define("EMAIL", "notsofast@xxx");

include('validate.class.php');

//assign post data to variables
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$location = trim($_POST['location']);
$value1 = trim($_POST['value1']);
$value2 = trim($_POST['value2']);
$value3 = trim($_POST['value3']);
$value4 = trim($_POST['value4']);
$value5 = trim($_POST['value5']);
$value6 = trim($_POST['value6']);
$value7 = trim($_POST['value7']);
$value8 = trim($_POST['value8']);
$value9 = trim($_POST['value9']);
$value10 = trim($_POST['value10']);
$value11 = trim($_POST['value11']);
$value12 = trim($_POST['value12']);
$value13 = trim($_POST['value13']);
$value14 = trim($_POST['value14']);
$message = trim($_POST['message']);

//start validating our form
$v = new validate();
$v->validateStr($name, "name", 3, 75);
$v->validateEmail($email, "email");
$v->validateStr($phone, "phone", 3, 75);
$v->validateStr($location, "location", 3, 75);
$v->validateStr($message, "message", 5, 1000);

if(!$v->hasErrors()) {
$header = "From: $email\n" . "Reply-To: $email\n";
$subject = "Form Submission";
$email_to = EMAIL;

$emailMessage = "Name: " . $name . "\n";
$emailMessage .= "Email: " . $email . "\n";
$emailMessage .= "Phone: " . $phone . "\n";
$emailMessage .= "Location: " . $location . "\n";
$emailMessage .= "Daytime Final Reads: " . $value1 . "\n";
$emailMessage .= "Overflow Coverage: " . $value2 . "\n";
$emailMessage .= "Tele-Locums: " . $value3 . "\n";
$emailMessage .= "On-site Coverage: " . $value4 . "\n";
$emailMessage .= "PET or PET/CT: " . $value5 . "\n";
$emailMessage .= "CT: " . $value6 . "\n";
$emailMessage .= "MR: " . $value7 . "\n";
$emailMessage .= "US: " . $value8 . "\n";
$emailMessage .= "US Echocardiogram: " . $value9 . "\n";
$emailMessage .= "NM: " . $value10 . "\n";
$emailMessage .= "XRAY: " . $value11 . "\n";
$emailMessage .= "Overread Service: " . $value12 . "\n";
$emailMessage .= "PACS ASP: " . $value13 . "\n";
$emailMessage .= "Radiology RFP: " . $value14 . "\n";
$emailMessage .= $message;

//use php's mail function to send the email
if(!mail($email_to, $subject ,$emailMessage ,$header)){
echo "mail did not send for some reason";
}
//grab the current url, append ?sent=yes to it and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header('Location: '.$url."?sent=yes");

} else {
//set the number of errors message
$service_message_text = $v->errorNumMessage();

//store the errors list in a variable
//*****************CHANGED THIS!!!**************
$serviceErrors = $v->displayErrors();

//get the individual error messages
$service_nameErr = $v->getError("name");
$service_emailErr = $v->getError("email");
$service_phoneErr = $v->getError("phone");
$service_locationErr = $v->getError("location");
$service_messageErr = $v->getError("message");
}//end error check
}
?>

<?php include 'header.php'; ?>
<!--content starts below here-->
<p class="contact"><span>Email Us: <a href="mailto:contact@southlakeradiology.com">contact@southlakeradiology.com</a></span>
</p>
<p class="contact"><span>Office: (866) 333-8443</span><span>Fax: (866) 316-0080</span>
</p>
<p class="contact"><span>For Radiology Services:</span>
</p>
<div id="services_form_wrap">
<span class="message"><?php echo $service_message_text; ?></span>
<?php echo $serviceErrors; ?>
<?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
<form id="services_form" method="post" action="contact.php"><fieldset><legend>Services:</legend><input type="hidden" name="formID" value="service"></input>
<p><label>Name:<br />
<input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
</label><br /><span class="errors"><?php echo $service_nameErr; ?></span></p>

<p><label>Email: <br />
<input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
</label><br /><span class="errors"><?php echo $service_emailErr ?></span></p>

<p><label>Phone: <br />
<input type="text" name="phone" class="textfield" title="phone" value="<?php echo htmlentities($phone); ?>" />
</label><br /><span class="errors"><?php echo $service_phoneErr ?></span></p>

<p><label>Location For Requested Services!: <br />
<input type="text" name="location" class="textfield" title="location" value="<?php echo htmlentities($location); ?>" />
</label><br /><span class="errors"><?php echo $service_locationErr ?></span></p>

<p class="check">
<input type="checkbox" name="service[]" title="Daytime Final Reads" value="<?php echo htmlentities($value1); ?>"/>
<span>Daytime Final Reads</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="Overflow Coverage" value="<?php echo htmlentities($value2); ?>"/>
<span>Overflow Coverage</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="Tele-Locums" value="<?php echo htmlentities($value3); ?>"/>
<span>Tele-Locums</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="On-site Coverage" value="<?php echo htmlentities($value4); ?>"/>
<span>On-site Coverage</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="PET or PET/CT" value="<?php echo htmlentities($value5); ?>"/>
<span>PET or PET/CT</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="CT" value="<?php echo htmlentities($value6); ?>"/>
<span>CT</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="MR" value="<?php echo htmlentities($value7); ?>"/>
<span>MR</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="US" value="<?php echo htmlentities($value8); ?>"/>
<span>US</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="US Echocardiogram" value="<?php echo htmlentities($value9); ?>"/>
<span>US Echocardiogram</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="NM" value="<?php echo htmlentities($value10); ?>"/>
<span>NM</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="XRAY" value="<?php echo htmlentities($value11); ?>"/>
<span>XRAY</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="Overread Service" value="<?php echo htmlentities($value12); ?>"/>
<span>Overread Service</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="PACS ASP" value="<?php echo htmlentities($value13); ?>"/>
<span>PACS ASP</span>
</p>

<p class="check">
<input type="checkbox" name="service[]" title="Radiology RFP" value="<?php echo htmlentities($value14); ?>"/>
<span>Radiology RFP</span>
</p><br style="clear:both" />

<p><label>Message: <br />
<textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
</label><br /><span class="errors"><?php echo $service_messageErr ?></span></p>
</fieldset>
<p class="butts"><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
</div>
<!--content ends above here-->
<?php include 'footer.php'; ?>

tangoforce
04-19-2012, 06:29 PM
As always, when debuigging the first place to start is var_dump(<variable>);

chevy_ls_6
04-19-2012, 07:17 PM
Evidently that is beyond my scope as well...what variable(s), and I just add that at the top of the script? I tried service and value, nada...could this be an issue with handling (retrieving) the 'service' array?

tangoforce
04-19-2012, 07:24 PM
First of all you want to know that the values for your checkboxes are being sent SO, you var_dump($_POST) and see what the post data contains. If your checkbox values are there then thats the first part solved. If they are not there then you have a problem.

It's common sense really, anything you want to check exists, any variable you can var_dump() to make sure it is set, see what type it is and what value it contains.

$_POST is an array so var dumping it will allow you to see if your values were sent to the script - which is the first step in debugging.

There is an art to programming in any computer language - debugging. You must become skilled at this in any language. Writing code and then asking people why it doesn't work won't always cut the mustart id you're doing paid jobs and you've not even grasped the basics of debugging. Taking paid work when you can't debug is very questionable.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum