我有联系表单,我想将我重定向到一个页面而不是向我显示"感谢您与我们联系"
现在的消息是" Mesajul成功了! Va vom contacta in maxim doua zile lucratoare。"我想删除该消息,当有人点击提交按钮被重定向到另一个页面而不是显示消息...
这是php代码
<?PHP
// Set header as json
header('Content-Type: application/json');
// Response
$data = array(
'type' => 'success',
'message' => 'Mesajul a fost trimis cu success! Va vom contacta in maxim doua zile lucratoare.',
'response' => 'success'
);
// Form rules
$rules = array(
'input-name' => 'required|min',
'input-email' => 'required|email',
'input-phone' => 'required|numeric'
);
// Rules messages
$messages = array(
'input-name' => array(
'required' => 'Numele este obligatoriu',
'min' => 'Numele trebuie sa aiba mai mult de 3 caractere'),
'input-email' => array(
'required' => 'Adresa de email este obligatorie',
'email' => 'Adresa de email nu este valida'),
'input-phone' => array(
'required' => 'Numarul de telefon este obligatoriu',
'numeric' => 'Numarul de telefon nu este valid')
);
// If no data is sent
if( !$_POST )
{
$data['type'] = 'danger';
$data['message'] = 'S-a produs o eroare! Va rugam incercati dinou.';
$data['response'] = 'fail';
}
// Check for spam
if( $data['type'] == 'success' && !isset($_POST['input-leaveblank']) && $_POST['input-leaveblank'] != 'foo' )
{
$data['type'] = 'success-foo';
$data['message'] = 'Mesajul a fost trimis.';
$data['response'] = 'success';
}
// If there had errors
if( $data['type'] == 'danger' || $data['type'] == 'success-foo' )
{
echo json_encode($data);
die();
}
// Validate form
foreach( $rules as $field => $rule )
{
foreach( explode("|", $rule) as $do_rule )
{
$error = false;
// Check input
switch ($do_rule)
{
case "required":
if( !isset($_POST[$field]) || $_POST[$field] == '' )
{
$error = 'required';
}
break;
case "min":
if( strlen($_POST[$field]) <= 3 )
{
$error = 'min';
}
break;
case "email":
if( !filter_var($_POST[$field], FILTER_VALIDATE_EMAIL) )
{
$error = 'email';
}
break;
case "numeric":
if( !is_numeric($_POST[$field]) )
{
$error = 'numeric';
}
break;
}
// If error show and die
if( $error != false )
{
$data['type'] = 'danger';
$data['message'] = $messages[$field][$error];
$data['response'] = 'fail';
echo json_encode($data);
die();
}
}
}
$attributes = $_POST;
$to = 'office@atelierdeweb.ro';
$subject = 'Formular contact Atelier de Web';
$headers = 'From: ' . $attributes['input-email'] . "\r\n" .
'Reply-To: ' . $attributes['input-email'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = 'Nume: ' . $attributes['input-name'] . "\r\n" .
'E-mail: ' . $attributes['input-email'] . "\r\n" .
'Telefon: ' . $attributes['input-phone'] . "\r\n" .
"\r\n" .
'Pachet potrivit: ' . $attributes['input-package'] . "\r\n" .
'Timp de lucru: ' . $attributes['input-endtime'] . "\r\n";
if( isset($attributes['input-services']) )
{
$message .= 'Servicii complementare: ';
foreach( $attributes['input-services'] as $service )
{
$message .= $service . ', ';
}
$message = substr($message, 0, -2) . "\r\n";
}
$message .= "\r\n\r\n" . $attributes['input-description'];
mail($to, $subject, $message, $headers);
// Return default data
echo json_encode($data);
?>
和HTML
<div class="form-group col-sm-12">
<button class="input-submit" type="submit" data-loading-text="Va rugam asteptati ..." data-complete-text="Mesajul a fost trimis" class="btn btn-default">Trimite cererea de oferta</button>
</div>