hierbij mijn form.
Ik krijg het niet voor elkaar de juiste waarde/data uit de variabele met het formulier meetesturen.
Doe ik iets verkeerd met het definieeren van de variabele?
<?php
$Group1 = $_POST["Group1"];
$Group2 = $_POST["Group2"];
// CONFIG YOUR E-MAIL
define('SEND_TO', '[email protected]');
define('SUBJECTS', 'Subject 1, Subject 2, Subject 3');
define('SUCCESS_MESSAGE', 'Thank you {name}.');
define('INBOX_MESSAGE', 'Name: {name} {enter} Company: {company} {enter} E-mail: {email} {enter} group1: {$group1} {enter} group2: {$group2} {enter} Phone number: {phone} {enter} group_01_options: {group_01_options} {enter} Comment: {enter} {comment}');
// CONFIG YOUR ERROR MESSAGES
define('ERROR_MESSAGE_NAME', '(Name can\'t be blank)');
define('ERROR_MESSAGE_EMAIL', '(E-mail can\'t be blank)');
define('ERROR_MESSAGE_EMAIL_INVALID', '(Email is invalid)');
define('ERROR_MESSAGE_PHONE_INVALID', '(Phone is invalid)');
define('ERROR_MESSAGE_COMMENT', '(Your comment can\'t be blank)');
define('ERROR_MESSAGE_CAPTCHA', '(Verification code can\'t be blank)');
define('ERROR_MESSAGE_CAPTCHA_INVALID', '(Verification code is invalid)');
// DON'T TOUCH BEGIN
@ini_set('session.use_cookies', '1');
@ini_set('session.use_trans_sid', 'false');
@session_set_cookie_params(0, '/');
@session_start();
if (ini_get('register_globals')) {
$globals = array('_SESSION');
foreach ($globals as $global) {
foreach ($GLOBALS[$global] as $key => $value) {
if ($value === @$GLOBALS[$key]) {
unset($GLOBALS[$key]);
}
}
}
}
@ini_set('magic_quotes_gpc', 'Off');
if (ini_get('magic_quotes_gpc')) {
function clean($data) {
if (is_array($data)) {
foreach ($data as $key => $value) {
$data[$key] = clean($value);
}
} else {
$data = stripslashes($data);
}
return $data;
}
$_POST = clean($_POST);
}
function php_self(){
if(isset($_SERVER['PATH_INFO']) && strlen($_SERVER['PATH_INFO'])> 0){
return substr($_SERVER['PHP_SELF'], 0, (strlen($_SERVER['PHP_SELF']) - @strlen($_SERVER['PATH_INFO'])));
}else{
return $_SERVER['PHP_SELF'];
}
}
$subjects = explode(',', SUBJECTS);
$error = FALSE;
$send = FALSE;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comment = $_POST['comment'];
$captcha = $_POST['captcha'];
$pfind = array(
'+',
'-',
' '
);
$phone_check = str_replace($pfind, '', $phone);
if(empty($name)){
$error_name = ERROR_MESSAGE_NAME;
$error = TRUE;
}
if(empty($email)){
$error_email = ERROR_MESSAGE_EMAIL;
$error = TRUE;
}elseif(!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $email)){
$error_email = ERROR_MESSAGE_EMAIL_INVALID;
$error = TRUE;
}
if(!empty($phone)){
if(!ctype_digit($phone_check)){
$error_phone = ERROR_MESSAGE_PHONE_INVALID;
$error = TRUE;
}
}
if(empty($comment)){
$error_comment = ERROR_MESSAGE_COMMENT;
$error = TRUE;
}
if(empty($captcha)){
$error_captcha = ERROR_MESSAGE_CAPTCHA;
$error = TRUE;
}elseif($_SESSION['captcha'] != $captcha){
$error_captcha = ERROR_MESSAGE_CAPTCHA_INVALID;
$error = TRUE;
}
if(!$error) {
if(strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
$ent = "\r\n";
}elseif(strtoupper(substr(PHP_OS, 0, 3) == 'MAC')) {
$ent = "\r";
}else{
$ent = "\n";
}
$find = array(
'{name}',
'{company}',
'{email}',
'{phone}',
'{group_01_options}',
'{comment}',
'{enter}'
);
$replace = array(
'name' => $name,
'company' => $company,
'email' => $email,
'phone' => $phone,
'group_01_options' => $group_01_options,
'commment' => $comment,
'enter' => $ent
);
$comment = str_replace($find, $replace, INBOX_MESSAGE);
$boundary = '----=_NextPart_' . md5(rand());
$headers = 'From: ' . $name . '<' . $email . '>' . $ent;
$headers .= 'X-Mailer: PHP/' . phpversion() . $ent;
$headers .= 'MIME-Version: 1.0' . $ent;
$headers .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $ent . $ent;
$message = '--' . $boundary . $ent;
$message .= 'Content-Type: text/plain; charset="utf-8"' . $ent;
$message .= 'Content-Transfer-Encoding: base64' . $ent . $ent;
$message .= chunk_split(base64_encode($comment));
ini_set('sendmail_from', $email);
mail(SEND_TO, $subject, strip_tags(html_entity_decode($message)), $headers);
$send = TRUE;
$success = str_replace($find, $replace, SUCCESS_MESSAGE);
}
}
// DON'T TOUCH END
?>
<?
// Database connection
$db_database = 'xxx';
$db_host = 'localhost';
$db_user = 'xxxx';
$db_pass = 'xxxx';
mysql_connect($db_host,$db_user,$db_pass) or die("Could not connect to MySQL (Main connection)");
mysql_select_db($db_database) or die("Could not connect to database (Main connection)");
$group_01_options = $_POST["group_01_options"];
function dual_linked_select(
$table, // Table to create linked selects from
$table_column_01, // Root category
$table_column_02, // Subcategory of the root category
$group_02_default_option_text // Default option text for the group 2 select
)
{
// Define globals
global $javascript;
global $group_01_options;
// Define variables
$javascript = null; // Hold
$group_01_options = null;//Hold
// Assembly of Javascript starts
$javascript .=<<<content
/* Linked Dropdown Selects Script Start */
function DefaultGroup2()
{
var x = document.getElementById("Group2");
x.length = 0;
VarGroup2 = document.getElementById("Group2");
VarGroup2.options[VarGroup2.options.length] = new Option("$group_02_default_option_text","");
document.getElementById("Group2").disabled = true;
}
function CheckGroup1Select()
{
// If no Group1 is selected clear the Group2 and set to default
if(document.getElementById("Group1").value == "")
{
// Clear the Group2 select and set to default value
DefaultGroup2();
}
content;
// Javascript
$group_01_query = "SELECT ".$table_column_01." FROM ".$table." GROUP BY ".$table_column_01;
$group_01_result = mysql_query($group_01_query) or die(mysql_error());
while($group_01 = mysql_fetch_array($group_01_result))
{
$group_01_options .= '<option value="'.$group_01[$table_column_01].'">'.$group_01[$table_column_01].'</option>'."\r\n";
$javascript .=<<<content
else if(document.getElementById("Group1").value == "$group_01[$table_column_01]")
{
// Clear the Group2 and set to default value
DefaultGroup2();
// Set variable options for Group2 select
VarGroup2 = document.getElementById("Group2");
content;
$group_02_query = "SELECT ".$table_column_02." FROM ".$table." WHERE ".$table_column_01." = '".$group_01[$table_column_01]."' GROUP BY ".$table_column_02;
$group_02_result = mysql_query($group_02_query) or die(mysql_error());
while($group_02 = mysql_fetch_array($group_02_result))
{
$javascript .=' VarGroup2.options[VarGroup2.options.length] = new Option("'.$group_02[$table_column_02].'","'.$group_02[$table_column_02].'");'."\r\n";
}
$javascript .=<<<content
document.getElementById("Group2").disabled = false;
}
content;
}
$javascript .=' }'."\r\n";
} // End of dual_linked_selects function
?>
<?
// execute dual_linked_selects_function
dual_linked_select('type','merk_id','type','Select...');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
<head>
<title>Contact Form</title>
<script type="text/javascript" language="JavaScript">
<? echo $javascript; ?>
</script>
<meta name="description" content="Contact Form" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="box">
<? if($send){ ?>
<div id="success"><h1>Email Sent Successfully.</h1><p><?=$success; ?></p></div>
<? }else{ ?>
<div id="form">
<? if($error) { ?><div class="error"><h1>Invalid Form Input</h1></div><? } ?>
<form method="post" action="<?=php_self() ?>">
<label for="name"><span class="required">*</span> Your Name
<? if(!empty($error_name)) { ?>
<span class="error_message"><?=$error_name ?></span>
<? }elseif(!empty($name)){ ?>
<img src="image/icon/accept.png" />
<? } ?>
</label>
<input name="name" type="text" id="name" size="30" <? if(!empty($name)){ ?> value="<?=$name ?>" <? } ?> class="text-input" />
<label for="company">Company
<? if(!empty($error_company)) { ?>
<span class="error_message"><?=$error_company?></span>
<? }elseif(!empty($company)){ ?>
<img src="image/icon/accept.png" />
<? } ?>
</label>
<input name="company" type="text" id="company" size="30" <? if(!empty($company)){ ?> value="<?=$company ?>" <? } ?> class="text-input" />
<label for="email"><span class="required">*</span> Email
<? if(!empty($error_email)) { ?>
<span class="error_message"><?=$error_email ?></span>
<? } elseif(!empty($email)){ ?>
<img src="image/icon/accept.png" />
<? } ?>
</label>
<input name="email" type="text" id="email" size="30" <? if(!empty($email)){ ?> value="<?=$email ?>" <? } ?> class="text-input" />
<label for="phone">Phone number
<? if(!empty($error_phone)) {?>
<span class="error_message"><?=$error_phone?></span>
<? }elseif(!empty($phone)){ ?>
<img src="image/icon/accept.png" />
<? } ?>
</label>
<input name="phone" type="text" id="phone" size="30" <? if(!empty($phone)){ ?> value="<?=$phone ?>"<? } ?> class="text-input" />
<select id="Group1" name="group1" onChange="CheckGroup1Select(this);">
<option value="">Select...</option>
<? echo $group_01_options; ?>
</select>
<br>
Group2:
<br>
<select id="Group2" name="group2"><? echo $group_01_options; ?></select>
<label for="comment"><span class="required">*</span> Your comment
<? if(!empty($error_comment)) { ?>
<span class="error_message"><?=$error_comment ?></span>
<? }elseif(!empty($comment)){ ?>
<img src="image/icon/accept.png" />
<? } ?>
</label>
<textarea name="comment" id="comment" rows="8"><? if(!empty($comment)){ echo $comment; } ?>
</textarea>
<label for="captcha"><span class="required">*</span> Are you human?
<? if(!empty($error_captcha)) { ?>
<span class="error_message"><?=$error_captcha ?></span>
<? } ?>
</label>
<div class="captcha"><img src="captcha.php" /></div>
<input name="captcha" type="text" id="captcha" size="30" class="text-input-captcha" />
<br />
<input type="submit" class="submit" value="Send" />
</form>
</div>
<? } ?>
</div>
</body>
</html>