SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    contact form php

    Hi!
    I have copied a template for the contact form, il runs ok, I can send and receive the message, but after having added the radio buttons, it's not OK,
    I wish someone can help me !
    Code PHP:
    <?php
     
    here is my template:
     
    // Initialise les variables
    $erreur = NULL;
    $info = NULL;
     
    if(!empty($_POST['pseudo']) AND !empty($_POST['email']) AND !empty($_POST['message'])){
     
    	extract($_POST);
     
    	 if (preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $email)){
     
    		$pseudo = htmlentities(addslashes($pseudo));
    		$email = htmlentities(addslashes($email));
    		$message = htmlentities(addslashes($message));
    		$message = 'Pseudo : '.$pseudo.' '."\n".' Message : '.$message.'';
    		$sujet = "Formulaire de contact";
    		$destinataire = "kiva1212@yahoo.fr";
    		$entete ='From: '.$email.'';
    		echo $entete;
     
    		mail($destinataire,$sujet,$message,$entete);
     
    		$info = 'Votre message à été envoyé';
     
    		unset($_POST);
    		unset($message);
    		unset($email);
    		unset($pseudo);
     
    	}
    	else{
    		$erreur = 'Votre adresse email est invalide';
    	}
     
     
    }
    else {
    	$erreur = 'Veuillez remplir tous les champs obligatoires *';
     
    }
    ?>
    Code HTML4Strict:
    <!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" xml:lang="fr" >
       <head>
           <title>Bienvenue sur mon site !</title>
           <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
           <link rel="stylesheet" media="screen" type="text/css" title="design" href="images/design.css" />
       </head>
       <body>
     
     
     
       <div id="contenu">
    		<!--Le contenu -->
     
    		<form method="post" id="formulaire_contact" target="">
     
    		<fieldset>
    		<legend> Formulaire de contact</legend>
    		<label for="pseudo">Name* : </label><input type="text" name="pseudo" id="pseudo" size="40" maxlength="38" value="<?php if(isset($pseudo)) echo $pseudo; ?>"/><br/>
    		<label for="email">Email* : </label><input type="text" name="email" id="email" size="40" maxlength="38" value="<?php if(isset($email)) echo $email; ?>"/><br/>
    		<label for="message">Message* : </label><input type="text" name="message" id="message" size="70" maxlength="68" value="<?php if(isset($message)) echo $message; ?>"/><br/>
     
    		<input type="submit" value="Envoyer"/><span style="color:red"> <?php echo $erreur; ?></span><span style="color:green"> <?php echo $info; ?></span>
    		</fieldset>
    		</form>
     
    here I add this radio buttons inside the fieldset, but it doesn't work
      <form id="form1" name="form1" method="post" action="">
      <p>
        <label>
          <input type="radio" name="RadioGroup1" value="man" id="RadioGroup1_0" />
          Lady</label>
        <label>
          <input type="radio" name="RadioGroup1" value="woman" id="RadioGroup1_1" />
        Man</label>
        <br />
      </p>
    </form>
    Last edited by TechnoBear; May 31, 2014 at 08:30. Reason: Code tags added

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    The problem is likely that you have two separate forms. Combine them into one.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your reply, I have aldreay combined the 2 forms, such as below, but it doesn't work

    Code PHP:
    <?php
     
    here is my template:
     
    // Initialise les variables
    $erreur = NULL;
    $info = NULL;
     
    if(!empty($_POST['pseudo']) AND !empty($_POST['email']) AND !empty($_POST['message'])){
     
    	extract($_POST);
     
    	 if (preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $email)){
     
    		$pseudo = htmlentities(addslashes($pseudo));
    		$email = htmlentities(addslashes($email));
    		$message = htmlentities(addslashes($message));
    		$message = 'Pseudo : '.$pseudo.' '."\n".' Message : '.$message.'';
    		$sujet = "Formulaire de contact";
    		$destinataire = "kiva1212@yahoo.fr";
    		$entete ='From: '.$email.'';
    		echo $entete;
     
    		mail($destinataire,$sujet,$message,$entete);
     
    		$info = 'Votre message à été envoyé';
     
    		unset($_POST);
    		unset($message);
    		unset($email);
    		unset($pseudo);
     
    	}
    	else{
    		$erreur = 'Votre adresse email est invalide';
    	}
     
     
    }
    else {
    	$erreur = 'Veuillez remplir tous les champs obligatoires *';
     
    }
    ?>
    Code HTML4Strict:
    <!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" xml:lang="fr" >
       <head>
           <title>Bienvenue sur mon site !</title>
           <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
           <link rel="stylesheet" media="screen" type="text/css" title="design" href="images/design.css" />
       </head>
       <body>
     
     
     
       <div id="contenu">
    		<!--Le contenu -->
     
    		<form method="post" id="formulaire_contact" target="">
     
    		<fieldset>
    		<legend> Formulaire de contact</legend>
                    <form id="form1" name="form1" method="post" action="">
      <p>
        <label>
          <input type="radio" name="RadioGroup1" value="man" id="RadioGroup1_0" />
          Lady</label>
        <label>
          <input type="radio" name="RadioGroup1" value="woman" id="RadioGroup1_1" />
        Man</label>
        <br />
      </p>
    </form>
    		<label for="pseudo">Name* : </label><input type="text" name="pseudo" id="pseudo" size="40" maxlength="38" value="<?php if(isset($pseudo)) echo $pseudo; ?>"/><br/>
    		<label for="email">Email* : </label><input type="text" name="email" id="email" size="40" maxlength="38" value="<?php if(isset($email)) echo $email; ?>"/><br/>
    		<label for="message">Message* : </label><input type="text" name="message" id="message" size="70" maxlength="68" value="<?php if(isset($message)) echo $message; ?>"/><br/>
     
    		<input type="submit" value="Envoyer"/><span style="color:red"> <?php echo $erreur; ?></span><span style="color:green"> <?php echo $info; ?></span>
    		</fieldset>
    		</form>
    Last edited by TechnoBear; Jun 1, 2014 at 01:23. Reason: Code tags added

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    United Kingdom
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to remove the first </form> in your code.

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,214
    Mentioned
    457 Post(s)
    Tagged
    8 Thread(s)
    You also can't just add extra form elements and hope that the PHP script will magically do something with them. You need to follow a similar pattern to the PHP already there. For example you could try adding in the red bits below:

    Code:
    $pseudo = htmlentities(addslashes($pseudo));
    $email = htmlentities(addslashes($email));
    $message = htmlentities(addslashes($message));
    if (isset($_POST["RadioGroup1"])) {
        $radioChoice = $_POST["RadioGroup1"];
    }
    $message = 'Pseudo : '.$pseudo.' '."\n".' Radio Choice : '.$radioChoice.''\n".' Message : '.$message.'';

  6. #6
    SitePoint Member
    Join Date
    May 2014
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Ralph,
    thanks, I have added your PHP script, but it still doesn't work


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •