Ajout redirection dans formulaire php

Fermé
Tang10 Messages postés 401 Date d'inscription lundi 8 janvier 2007 Statut Membre Dernière intervention 5 août 2014 - 7 févr. 2011 à 22:08
 Utilisateur anonyme - 7 févr. 2011 à 22:19
Bonjour,
Je souhaiterai modifier le formulaire ci-dessous pour qu'il renvoi vers une page web précise après validation.

Si quelqu'un pourrais m'aider s'il vous plaît.

Merci !

<?php

//==================================================================================================================================================
// Configuration

$form_type = "Fenêtres";

$form_mail = "contact@";

$form_message = "
Nous avons bien reçu votre demande et vous en remercions.<br />
<br />
<br />
Cordialement,<br />
L'équipe
";

$form_display_datas = array(
"Informations générales" => array(
"Informations sur le dépositaire" => array("firstname","lastname","phone1","phone2"),
"Localisation" => array("address","address_complement","zipcode","city"),
),
"Votre projet" => array(
"Fenêtres" => array("exterior_joinery","desired_materials","woodwork_size","product_range","desired_service"),
//"Pompe à chaleur" => array("heat_pump","heating_system","heat_area","heat_room_number"),
//"Climatisation" => array("conditioning_type","cool_area","cool_room_number"),
//"Panneaux photovoltaïques" => array("power_required","living_condo","urban_site","isolated_site","roof_surface"),
//"Energie solaire" => array("needs","existing_facility","household_number","roof_information","home_type"),
),
"Informations complémentaires" => array(
"" => array("status","work_begin","work_financing","building_type"),
),
"Commentaires" => array(
"" => array("comments"),
),
);

$form_field_datas = array(
// Informations sur le dépositaire
"firstname" => array("text" => "Prénom", "type" => "text"),
"lastname" => array("text" => "Nom", "type" => "text"),
"phone1" => array("text" => "Tel1", "type" => "text"),
"phone2" => array("text" => "Tel2", "type" => "text"),
// Localisation
"address" => array("text" => "Adresse", "type" => "text"),
"address_complement" => array("text" => "Complément d'adresse", "type" => "text"),
"zipcode" => array("text" => "Code postal","text", "type" => "text"),
"city" => array("text" => "Commune","text", "type" => "text"),
// Fenêtres
"exterior_joinery" => array("text" => "Type de menuiseries extérieures", "type" => "select", "datas" => "Fenêtre(s),Portes d'entrée,Portes fenêtres & baies coulissante,Autre"),
"desired_materials" => array("text" => "Matériaux souhaités", "type" => "select", "datas" => "A définir,PVC,Aluminium,Bois"),
"woodwork_size" => array("text" => "Quantités et tailles des menuiseries", "type" => "text"),
"product_range" => array("text" => "Gamme de produit", "type" => "select", "datas" => "Moyen - Haut de gamme,Entrée - Moyenne gamme,A définir"),
"desired_service" => array("text" => "Prestation souhaitée", "type" => "select", "datas" => "Fourniture et Pose,Fourniture seule,Pose seule,A définir"),
// Pompe à chaleur
"heat_pump" => array("text" => "Pompe à chaleur souhaitée", "type" => "select", "datas" => "Pompe à chaleur AIR - EAU,Pompe à chaleur EAU - EAU"),
"heating_system" => array("text" => "Type de système de chauffage", "type" => "select", "datas" => "Radiateur à eau,Plancher chauffant"),
"heat_area" => array("text" => "Surface totale à chauffer", "type"=> "text", "post" => "m²"),
"heat_room_number" => array("text" => "Nombre de pièces","type"=> "text"),
// Climatisation
"conditioning_type" => array("text" => "Type de climatisation souhaitée", "type" => "select", "datas" => "Réversible chaud - froid,Split,Console,Gainable,A définir"),
"cool_area" => array("text" => "Surface totale à climatiser", "type"=> "text","post" => "m²"),
"cool_room_number" => array("text" => "Nombre de pièces à climatiser", "type"=> "text"),
// Panneaux photovoltaïques
"power_required" => array("text" => "Puissance demandée", "type" => "select", "datas" => "Inférieur à 3Kwc,Inférieur à 6Kwc,Inférieur à 36Kwc"),
"living_condo" => array("text" => "Habitez-vous en copropriété", "type" => "select", "datas" => "Oui,Non"),
"urban_site" => array("text" => "Le chantier est situé en milieu urbain", "type" => "select", "datas" => "Oui,Non"),
"isolated_site" => array("text" => "Site isolé électriquement", "type" => "select", "datas" => "Oui,Non"),
"roof_surface" => array("text" => "Surface de votre toiture", "type" => "text", "post" => "m²"),
// Energie solaire
"needs" => array("text" => "Vos besoins", "type" => "select", "datas" => "Chauffage habitation,Eau chaude sanitaire,Chauffage piscine et/ou SPA,Autre"),
"existing_facility" => array("text" => "Type d'installation existante", "type" => "select", "datas" => "Autre,Chauffage électrique,Chauffage gaz ou fioul,Aucune"),
"household_number" => array("text" => "Nombre de personnes dans le foyer","type"=>"text" ),
"roof_information" => array("text" => "Informations concernant la surface de votre toiture","type"=>"text", "post" => "m²"),
"home_type" => array("text" => "Votre logement est actuellement", "type" => "select", "datas" => "Individuel,Collectif,Entrepôt,Autre"),
// Informations complémentaires
"status" => array("text" => "Vous êtes", "type" => "select", "datas" => "Propriétaire,Locataire,Autre"),
"work_begin" => array("text" => "Début des travaux", "type" => "select", "datas" => "A définir,Dès que possible,Dans le mois,De 2 à 3 mois,de 3 à 6 moi,Plus de 6 mois"),
"work_financing" => array("text" => "Financement des travaux", "type" => "select", "datas" => "Comptant,Crédit,A définir"),
"building_type" => array("text" => "Type de bâtiment concerné", "type" => "select", "datas" => "Maison,Locaux professionnels,Autre"),
// Commentaires
"comments" => array("text" => "Commentaires", "type" => "textarea"),
);

//==================================================================================================================================================
// Ne pas editer

$show_form = true;
if(isset($_POST["form_is_submitted"])) {
$error = false;
foreach($_POST as $key => $value) {
if(trim($value) == "" && !in_array($key,array("phone2","address_complement","comments"))) {
$error = true;
$form_field_datas[$key]["error"] = "Veuillez saisir le champs <i>".$form_field_datas[$key]["text"]."</i>";
}
}
if(!$error) {
$show_form = false;

// Save datas into the database
$form_query = "INSERT INTO devis "
."('id','date_sent','quote_type','".implode("',\n'",array_keys($form_field_datas))."') "
."VALUES ('',NOW(),'$form_type'";
foreach(array_keys($form_field_datas) as $form_field) {
if(isset($_POST[$form_field])) {
$value = $_POST[$form_field];
//$value = str_replace("'","\'",$value);
$form_query .= ",\n'$value'";
}
else {
$form_query .= ",\n''";
}
}
$form_query .= ");";

//echo "form_query: $form_query";

global $wpdb;
$wpdb->query($form_query);

// Send email
$form_subject = "Demande de devis ($form_type)";
$form_body = "Bonjour,<br /><br />\n";
$form_body .= ucfirst($_POST["firstname"])." ".ucfirst($_POST["lastname"])." vient de demander un devis dans la catégorie: $form_type<br /><br />\n";
$form_body .= "Voici ses informations:<br /><br />\n";
$form_body .= "<table>\n";
foreach($form_display_datas as $form_category => $form_sub_categories) {
$form_body .= "<tr><td colspan=\"2\" align=\"center\"><h3>".$form_category."</h3></td></tr>\n";
foreach($form_sub_categories as $form_sub_category => $form_fields) {
if(trim($form_sub_category) != "") {
$form_body .= "<tr><td colspan=\"2\"><b>".$form_sub_category."</b></td></tr>\n";
}
foreach($form_fields as $form_field) {
$form_body .= get_form_field($form_field,$form_field_datas);
}
}
}
$form_body .= "</table>\n";

mail(
$form_mail,
form_string_encode($form_subject),
form_string_encode($form_body),
"Mime-Version: 1.0\r\n"
."Content-Type: text/html; charset=\"utf-8\"\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: onlinehome.fr\r\n"
);

echo $form_message;
}
}

function form_string_encode($str) {
if(!form_string_isutf8($str)) {
$str = utf8_encode($str);
}
if(form_string_isutf8(utf8_decode($str))) {
$str = utf8_decode($str);
}
return $str;
}

function form_string_isutf8($str) {
return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $str);
}

function get_form_field($name, $form_field_datas)
{
$value = $_POST[$name];
if($name == "comments") $value = nl2br($value);
return "<tr><td width=\"300\">".$form_field_datas[$name]["text"]."</td><td>".$value."</td></tr>";
}

function show_form_field($name, $form_field_datas)
{
$form_field_data = $form_field_datas[$name];
$type = $form_field_data["type"];
echo "<tr>\n";
echo "<td width=\"300\">".$form_field_data["text"]."</td>\n";
echo "<td align=\"left\">";

$value = (isset($_POST[$name])) ? trim($_POST[$name]) : "";

switch($type) {
case "text":
echo "<input type=\"text\" name=\"$name\" value=\"$value\" />";
break;
case "select":
echo "<select name=\"$name\">";
echo "<option value=\"\"></option>";
foreach(split(",",$form_field_data["datas"]) as $data) {
$selected = ($data == $value) ? "selected" : "";
echo "<option value=\"$data\" $selected >$data</option>";
}
echo "</select>";
break;
case "radio":
$count = 0;
foreach(split(",",$form_field_data["datas"]) as $data) {
$checked = ($data == $value) ? "checked" : "";
echo "<input type=\"radio\" name=\"$name\" value=\"$data\" id=\"$name-$count\" $checked /><label for=\"$name-$count\">$data</label>";
$count++;
}
break;
case "textarea":
echo "<textarea name=\"$name\" cols=\"40\" rows=\"10\">".$value."</textarea>";
break;
}
if(isset($form_field_data["post"])) {
echo " ".$form_field_data["post"];
}
echo "</td>\n";
echo "</tr>\n";
if(isset($form_field_data["error"])) {
echo "<tr><td colspan=\"2\" style=\"color: red\">".$form_field_data["error"]."</td></tr>";
}
}

if($show_form) {

?>

<a href="http://s347585904.onlinehome.fr/wp-content/uploads/2010/11/Fenetres.png"><img class="aligncenter size-full wp-image-134" title="Fenetres" src="http://s347585904.onlinehome.fr/wp-content/uploads/2010/11/Fenetres.png" alt="" width="683" height="59" /></a>

Conseil, vente et pose de fenêtres et baies vitrées pour une meilleure isolation.

Vérandas, portails, stores, portes et fenêtres, garde-corps, abri fumeurs, ECOSOLIA propose des produits de menuiserie aluminium ou PVC de grande qualité mis en oeuvre par des professionnels. Quel que soit leur matériau (Alu ou PVC), le remplacement de vos fenêtres vous apporte un réel bien-être.

Plus d'informations sur nos fenêtres.

<center>

<form action="" name="form" method="post" style="margin-top: 50px">
<table>
<?php
foreach($form_display_datas as $category => $sub_categories) {
echo "<tr><td colspan=\"2\"><br /><h3>".$category."</h3></td></tr>";
foreach($sub_categories as $sub_category => $form_fields) {
if(trim($sub_category) != "") {
echo "<tr><td colspan=\"2\"><b>".$sub_category."</b></td></tr>";
}
foreach($form_fields as $form_field) {
show_form_field($form_field,$form_field_datas);
}
}
}
?>
<tr><td colspan="2" align="right"><input type="submit" value="Valider" name="form_is_submitted" /></tr>
</table>
</form>

</center>

<?php
} // show form
?>

1 réponse

Utilisateur anonyme
7 févr. 2011 à 22:19
lorsque ton formulaire sera bien validé , tu ajoute cette ligne dans ton code php:

header("Location:cible.php");

cible : la page de redirection.

J'espere t'avoir aidé
0