MyBB Community Forums

Full Version: Contact form
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I understand this is outside of mybb, but i know that mybb must use a similar way for contacting

Below is my contact form for my website... When a field is left empty, it doesn't display the alert message correctly, it just says "NaN"

help please

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = '[email protected]';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

// EMPTY FIELD CHECK
if( (empty($field_name)) || (empty($field_email)) || (empty($field_message)) ) { ?>
<script language="javascript" type="text/javascript">
	 	alert("Fields marked with a "*" are required. You will be redirected shortly");
		window.location = 'http://www.imatthew.webege.com/contact';
    </script>
<?php
}
// SUCCESS
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
		alert('Thank you for the message. We will contact you shortly.');
		window.location = 'http://www.imatthew.webege.com/contact';
	</script>
<?php
}
// FAILURE
else { ?>
<script language="javascript" type="text/javascript">
		alert('Message failed. Please, send an email to [email protected]');
		window.location = 'http://www.imatthew.webege.com/contact';
	</script>
<?php
}
?>
What exactly do you mean it just says "NaN"? Also, you're sending the mail before checking for empty fields and stuff. It should be the other way around.
well the alert message says NaN... would it be easier to just recreate the contact form entirely?
I would say so. I'm not sure why you're trying to use javascript to show the error anyway. Why not just use the contact form plugin or take a look at the page manager page?
i wanted to use the script to display it as an alert... ideally i wanna do something like twitter with the drop down bar at the top
You'd be better off just outputting the error using pure PHP and styling it via CSS.
well i dont have a lot of php knowledge.. i found this contact form via a google search and made a few tweaks to it
Ah. I'll take aproper look at the code after my lecture and fix it up if I get time Smile
Don't know if it will help, but I have a page which uses check box's, and if you miss one box you will get NaN. So the NaN could mean you have not entered all information or ticked all box's.

Just a thought.
(2012-10-02, 08:36 AM)euantor Wrote: [ -> ]Ah. I'll take aproper look at the code after my lecture and fix it up if I get time Smile

thanks a bunch.