Contact Form help

Hi everybody,

I really need your guys help as i have built a website and have added two contact forms. Which i managed to get from a tutorial off youtube. Now the contact duplicated the forms and have put one on the home and contact form page. they both work and is able to send the emails but on the home page it loses its footer and introduction part and on the contact form page it looses its footer. And I have run out off ideas on what to do.

So if anyone has got a solution of fixing it or better way of inputting a contact form pleeessssee giv me a shout

many thanks

Anthony

Let me kno if you want code or link to the website

Can you be more specific?

What do you mean “it looses its footer”? (BTW, the correct word in this case is lose, not loose)
If the footer on the page(s) disappears when you insert the form, then I would suspect you have not properly closed an HTML tag in the form. Or you have inserted the form in such a way that it leaves a dangling tag.
Have you viewed the page(s) in various browsers? Some browsers are more forgiving of such errors.
Have you tried a tool like Firebug or the “view element” in Chrome to spot the error?

Gonna need to see the code to answer the question. Entirely too vague.

this is the website: www.all-wired.co.uk

Looks like you’ve got a malformed <script> tag when you submit the form… what’s the actual code that handles the submission?


<?php

// Set email variables
$email_to = '';
$email_subject = 'Form submission';

// Set required fields
$required_fields = array('fullname','contact','email','comment');

// set error messages
$error_messages = array(
	'fullname' => 'Please enter a Name to proceed.',
	'contact' => 'Please enter a Contact Number to proceed.',
	'email' => 'Please enter a valid Email Address to continue.',
	'comment' => 'Please enter your Message to continue.'
);

// Set form status
$form_complete = FALSE;

// configure validation array
$validation = array();

// check form submittal
if(!empty($_POST)) {
	// Sanitise POST array
	foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));
	
	// Loop into required fields and make sure they match our needs
	foreach($required_fields as $field) {		
		// the field has been submitted?
		if(!array_key_exists($field, $_POST)) array_push($validation, $field);
		
		// check there is information in the field?
		if($_POST[$field] == '') array_push($validation, $field);
		
		// validate the email address supplied
		if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
	}
	
	// basic validation result
	if(count($validation) == 0) {
		// Prepare our content string
		$email_content = 'New Website Comment: ' . "\
\
";
		
		// simple email content
		foreach($_POST as $key => $value) {
			if($key != 'submit') $email_content .= $key . ': ' . $value . "\
";
		}
		
		// if validation passed ok then send the email
		mail($email_to, $email_subject, $email_content);
		
		// Update form switch
		$form_complete = TRUE;
	}
}

function validate_email_address($email = FALSE) {
	return (preg_match('/^[^@\\s]+@([-a-z0-9]+\\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
}

function remove_email_injection($field = FALSE) {
   return (str_ireplace(array("\\r", "\
", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
}

?>

is this the one?

k, not seeing anything glaringly obvious that would cause that… step back a layer and show me the code for the form itself? (PS: wrap them in [ PHP ] [ /PHP ] tags (no spaces))

<div id=“formwrap”>
<div id=“form”>
<?php if($form_complete === FALSE): ?>
<form action=“contactform.php” method=“post” id=“comments_form”>
<div class=“row”>
<div class=“label”>Your Name</div><!-----end .label----->
<div class=“input”>
<input type=“text” id=“fullname” class=“detail” name=“fullname” value=“<?php echo isset($_POST[‘fullname’])? $_POST[‘fullname’] : ‘’; ?>” /><?php if(in_array(‘fullname’, $validation)): ?><span class=“error”><?php echo $error_messages[‘fullname’]; ?></span><?php endif; ?>
</div><!-----end .input----->
</div><!-----end .row----->

&lt;div class="row"&gt;
&lt;div class="label"&gt;Contact Number&lt;/div&gt;&lt;!-----end .label-----&gt;
&lt;div class="input"&gt;
&lt;input type="text" id="contact" class="detail" name="contact" value="&lt;?php echo isset($_POST['contact'])? $_POST['contact'] : ''; ?&gt;" /&gt;&lt;?php if(in_array('contact', $validation)): ?&gt;&lt;span class="error"&gt;&lt;?php echo $error_messages['contact']; ?&gt;&lt;/span&gt;&lt;?php endif; ?&gt;   
&lt;/div&gt;&lt;!-----end .input-----&gt;
&lt;/div&gt;&lt;!-----end .row-----&gt;

&lt;div class="row"&gt;
&lt;div class="label"&gt;Your Email Address&lt;/div&gt;&lt;!-----end .label-----&gt;
&lt;div class="input"&gt;
&lt;input type="text" id="email" class="detail" name="email" value="&lt;?php echo isset($_POST['email'])? $_POST['email'] : ''; ?&gt;" /&gt;&lt;?php if(in_array('email', $validation)): ?&gt;&lt;span class="error"&gt;&lt;?php echo $error_messages['email']; ?&gt;&lt;/span&gt;&lt;?php endif; ?&gt;   
&lt;/div&gt;&lt;!-----end .input-----&gt;
&lt;/div&gt;&lt;!-----end .row-----&gt;

&lt;div class="row"&gt;
&lt;div class="label"&gt;Your Message&lt;/div&gt;&lt;!-----end .label-----&gt;
&lt;div class="input"&gt;
&lt;textarea id="comment" name="comment" class="mess"&gt;&lt;?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?&gt;&lt;/textarea&gt;&lt;?php if(in_array('comment', $validation)): ?&gt;&lt;span class="error"&gt;&lt;?php echo $error_messages['comment']; ?&gt;&lt;/span&gt;&lt;?php endif; ?&gt;   
&lt;/div&gt;&lt;!-----end .input-----&gt;
&lt;/div&gt;&lt;!-----end .row-----&gt;

&lt;div class="submit"&gt;
&lt;input type="submit" id="submit" name="submit" value="Send Message" /&gt;    
&lt;/form&gt;	
&lt;?php else: ?&gt;

<p style=" font-size:25px; font-family:Arial, Helvetica, sans-serif; color:#333333; margin-left:25px;">Thank You For Your Request</p>
<script type=“text/javascript”>
setTimeout(‘ourRedirect()’, 5000)
function ourRedirect(){
location.href=‘contactform.php’
}
<?php endif; ?>

</div><!-----end .submit----->

</div><!-----end form----->
</div><!-----end of form wrap----->

Ah, there it is…


<?php else: ?>
<p style=" font-size:25px; font-family:Arial, Helvetica, sans-serif; color:#333333; margin-left:25px;">Thank You For Your Request</p>
<[COLOR="#FF0000"]script[/COLOR] type="text/javascript">
setTimeout('ourRedirect()', 5000)
function ourRedirect(){
location.href='contactform.php'
}
<?php endif; ?>

Do you see a </script> on the end of that 4-line javascript code? I dont…

O yeah, thanks Star Lion. But Ive jus added the </script> but the footer still moves on both the home and contact form page, if you try it.

is it possible to add a reCAPTCHA to this form by any chance? if so, how do I go about adding one?

Ew, captcha is horrible. Have a read of this thread for much better options:

Mkay, this time it’s an errant </div> tag…

[QUOTE=Tony_b;5153635]

    <[COLOR="#FF0000"]div[/COLOR] class="submit">
    <input type="submit" id="submit" name="submit" value="Send Message" />    
    </form>	
	<?php else: ?>
<p style=" font-size:25px; font-family:Arial, Helvetica, sans-serif; color:#333333; margin-left:25px;">Thank You For Your Request</p>
<script type="text/javascript">
setTimeout('ourRedirect()', 5000)
function ourRedirect(){
 location.href='contactform.php'
 }
<?php endif; ?>


  </[COLOR="#FF0000"]div[/COLOR]><!-----end .submit----->

Notice how the opening tag for the div is inside the “if” part of the if/else? Well, when we run the ELSE (the form has been submitted), there is no opening tag for that </div>, so it closes the next element up the chain - which causes your alignment issue. Move the offending line (the bottom one) to just below the submit button’s input tag.