Ik ben nogal nieuw in het webdesignen en maakte een website als vriendendienst.
Nu heb ik een contactformulier ontworpen (aan de hand van een youtube filmpje), maar jammer genoeg werkt mijn php code niet in mijn html pagina.
Ten eerste ontbreekt de kleurencode in de phpcode en ten tweede verschijnen er stukjes tekst van de php code op de html pagina.
Ik heb al verschillende oplossingen opgezocht, maar nog steeds werkt het niet.
Kunnen jullie mij helpen?
Hieronder volgt de code van mijn document (ik heb het menu & de stijlen eruit gelaten.)
Alvast bedankt!
Mvg,
Chloë
<?php
session_start();
// Set email variables
$email_to = '[email protected]';
$email_subject = 'Contactformulier website';
// Set required fields
$required_fields = array('naam','voornaam','email','bericht');
// set error messages
$error_messages = array(
'naam' => 'Gelieve een naam op te geven.',
'voornaam' => 'Gelieven een voornaam op te geven.',
'email' => 'Gelieve een e-mail adres op te geven.',
'bericht' => 'Gelieve een bericht in te geven.'
);
// 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: ' . "\n\n";
// simple email content
foreach($_POST as $key => $value) {
if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
}
// 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", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0014)about:internet -->
<html>
<head>
<title>contact3.png</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.0/mootools-yui-compressed.js"></script>
<script type="text/javascript" src="validation/validation.js></script>
<script type="text/javascript">
var nameError = '<?php echo $error_messages['naam']; ?>';
var prenameError = '<?php echo $error_messages['voornaam']; ?>';
var emailError = '<?php echo $error_messages['email']; ?>';
var commentError = '<?php echo $error_messages['bericht']; ?>';
</script>
<style type="text/css">
</style>
<script type="text/javascript">
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
</head>
<body>
<div class="container">
<table style="display: inline-table;" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="960">
<td background="images/contact3_r1_c1.png"> <table width="800" height="40" border="0" align="center" style="margin-bottom: 0px; position: relative; bottom: 10px; left: 0px; top: 60px; right: 0px;">
<tr>
<td>
<div id="formWrap">
<table width="800" height="250" border="0" align="center" style="margin-bottom: 0px; position: relative; bottom: 10px; left: 0px; top: 60px; right: 0px; margin-left: 25px;">
<?php if($form_complete === FALSE): ?>
<form action="contact.html" method="post" id="comments_form">
<tr>
<td height="31" class="contactnaam"> Naam </td>
<td><input type="text"id="naam" class="detail" name="naam" 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; ?></td>
</tr>
<tr>
<td height="31" class="contactnaam"> Voornaam </td>
<td> <input type="text"id="voornaam" class="detail" name="voornaam" 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; ?> </td>
</tr>
<tr>
<td height="27" class="contactnaam"> Email </td>
<td> <input type="text"id="email" class="detail" name="email" value"<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>"/><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?> </td>
</tr>
<tr>
<td height="27" class="contactnaam"> Onderwerp </td>
<td> <input type="text"id="onderwerp" class="detail" name="onderwerp" 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; ?></td>
</tr>
<tr>
<td class="contactnaam"> Bericht </td>
<td> <textarea id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea><?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?> </td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" class"submit" name="submit" value="Verzenden" />
</form>
</td>
<?php else: ?>
<p style="font-size:25px; font-family:actor, Arial; color:#0095AD; margin-left:10px">Danku voor uw bericht.</p>
<script type="text/javascript">
setTimeout('ourRedirect()',5000)
function ourRedirect () {
location.href='index.html'
}
</script>
<?php endif; ?>
</table>
</div>
</td> <td><img src="images/spacer.gif" width="1" height="771" alt=""></td>
</tr>
<tr>
<td background="images/contact3_r3_c1.png"></td>
<td><img src="images/spacer.gif" width="1" height="26" alt=""></td>
</tr>
</table>
</div>
</body>
</html>