Page 1 of 1

Form + Group Members

Posted: Mon Feb 15, 2010 3:17 am
by Midlandcanary
Hi Guys,

Im currently building an activities site where people can book a bike trip in the uk. The trouble i am having is that there is often multiple people in a group with different statistics.

Ive managed to build a system where a group member can be added however the code will not send the information onto my e-mail :-( I have asked around on a few other forums and they have no clue :-(

Any Ideas?

Code: Select all

<?php
session_start();
 
function mres($val)
{
    return mysql_real_escape_string($val);
}
 
if (empty($_SESSION["rows"]))
    $_SESSION["rows"] = 1;
 
if (!empty($_POST["add"])) {
    $_SESSION["rows"]++;
}
 
if (!empty($_POST["remove"])) {
    $_SESSION["rows"]--;
}
 
if (isset($_POST["SUBMIT"])) {
    $message='';
 
    $message.="Name:\n" . htmlspecialchars($_POST["Name"])."\n";
    $message.="Address:\n" . htmlspecialchars($_POST["Address"])."\n";
    $message.="Phone:\n" . htmlspecialchars($_POST["Phone"])."\n";
    $message.="EMAIL:\n" . htmlspecialchars($_POST["EMAIL"])."\n";
    $message.="Date:\n" . htmlspecialchars($_POST["Date"])."\n";
 
 
    // collect group values!
    for($i = 0;$i < $_SESSION["rows"];$i++) {
 
    $message .= ($i + 1) . ". member:\n";
    $message .= "Name :\n " .  htmlspecialchars($_POST["GROUPMEMBER_Name"][$i]) . "\n";
    $message .= "Sex :\n " . htmlspecialchars($_POST["GROUPMEMBER_Sex"][$i]). "\n";
    $message .= "Age :\n " .  htmlspecialchars($_POST["GROUPMEMBER_Age"][$i]) . "\n";
    $message .= "Height :\n " . htmlspecialchars($_POST["GROUPMEMBER_Height"][$i]). "\n";
    $message .= "biketype :\n " . htmlspecialchars($_POST["GROUPMEMBER_biketype"][$i]) . "\n";
    $message .= "\n------------------------\n\n";
 
    }
 
    /*print"<pre>";
    print_r($_POST);
    print"</pre>";
    print nl2br($message);
    */
    $email="midlandcanary@gmail.com";  
    
    $headers = 'From: '.$email . "\r\n" .
    'Reply-To: '.$email . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
     ini_set( 'sendmail_from', $email ); 
     mail($email , "Subject: subject", $message, $headers );
 
     unset($_SESSION["rows"]);
     Header("Location:  bookingform.php");
     die();
}
 
 
 
if (isset($_POST))
    $P = $_POST;
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Rutland Activities | Cycle Hire | Climbing Wall | High Ropes</title>
 
 
<link href="/testing1/activitystyles.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript">
</script>
</head>
 
<body>
 
 
<div id="container">
    <div id="header">
        <div id="logo">
        <img src="/testing1/RutlandActivitiesImages/logo.png" alt="Rutland
 
Activities" width="400" height="90" />        </div>
        <div id="headermid"><img
 
src="/testing1/RutlandActivitiesImages/icons.gif" alt="Rutland Activities" width="267"
 
height="80" /></div>
        <div class="contactdetails">Call now! 01780 460 060<br /><br />
      email: info@rutlandactivities.co.uk</div>
      </div>
<div id="menubarpos">
    <div id="menubar">
<script src="Scripts/ie6dropdownfix.js" type="text/javascript"></script>
    <ul id="nav">
        <li class="bookonlineicon"><a href="">Book Online</a>        </li>
        <li><a href="">Activities</a>
            <ul>
                <li><a href="">Cycle Hire</a></li>
                <li><a href="">Climbing</a></li>
                <li><a href="">Aerial Assault Course</a></li>
                <li><a href="">Traverse Wall</a></li>
                <li><a href="">Orienteering</a></li>
            </ul>
        </li>
        <li><a href="">Group Visits</a>
            <ul>
                <li><a href="">Schools</a></li>
                <li><a href="">Corporate/Teambuilding</a></li>
                <li><a href="">Parties</a></li>
            </ul>
        </li>
        <li><a href="">Events</a>
            <ul>
                <li><a href="">Events Calendar</a></li>
                <li><a href="">Gallery</a></li>
            </ul>
        </li>
        <li><a href="">Feedback</a>        </li>
        <li><a href="">Where To Find Us</a>
            <ul>
                <li><a href="">Whitwell</a></li>
                <li><a href="">Normanton</a></li>
                <li><a href="">Grafham</a></li>
            </ul>
        </li>
    </ul>
    </div>
    </div>
    <div id="background">
    <div id="mainimage">
      <script type="text/javascript">
AC_FL_RunContent(
 
'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7
 
,0,19,0','width','999','height','319','title','Rutland
 
Activities','src','/testing1/RutlandActivitiesImages/mainmovie','quality','high','plugins
 
page','http://www.macromedia.com/go/getflashplayer','wmode','transparent','movie','/testi
 
ng1/RutlandActivitiesImages/mainmovie' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0
 
,19,0" width="999" height="319" title="Rutland Activities">
        <param name="movie" value="/testing1/RutlandActivitiesImages/mainmovie.swf" />
        <param name="quality" value="high" />
        <param name="wmode" value="transparent" />
        <embed src="/testing1/RutlandActivitiesImages/mainmovie.swf" width="999"
 
height="319" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
 
type="application/x-shockwave-flash" wmode="transparent"></embed>
      </object>
    </noscript>
    </div>
    <!--<div id="maincontenttop">    </div>-->
 
<div id="maincontentheader"><form method="POST">
 
<table border="0" width=100%  >
    <tr><td width="7%" >Main Contact:</td>
    </tr>
    <tr>
        <td  >Name:&nbsp;</td>
      <td width="18%"  ><input name="Name" value="<?php echo isset($P["Name"])?strips($P["Name"]):'' ?>"></td>
    </tr>
    <tr>
        <td  align="top">Address:&nbsp;</td>
        <td  ><textarea input name="Address"  maxlength="1000" cols="25"
 
rows="6"><?php echo isset($P["Address"])?strips($P["Address"]):'' ?></textarea></td>
    </tr>
    <tr>
        <td  >Phone Number:&nbsp;</td>
        <td  ><input name="Phone" size="20" maxlength="15"  value="<?php echo isset($P["Phone"])?strips($P["Phone"]):'' ?>"></td>
    </tr>
    <tr>
        <td  >E-Mail:&nbsp;</td>
        <td  ><input name="EMAIL" size="20" maxlength="20" value="<?php echo isset($P["EMAIL"])?strips($P["EMAIL"]):'' ?>"></td>
    </tr>
    <tr>
        <td   >Date:&nbsp;</td>
        <td  ><input name="Date" value="<?php echo isset($P["Date"])?strips($P["Date"]):'' ?>"></td>
    </tr>
<table id="dataTable">
    <tr id="dataTable" ></tr>
    <tr><td>Group Members:
 
 
<input name="add" type="submit" value="add new member">
<?php
if ($_SESSION["rows"] > 1) {
 
    ?>
<input name="remove" type="submit" value="remove one member">
<?php
}
 
?>
 
    </td></tr>
 
 
    <?php
 
 
function strips($val)
{
    if (get_magic_quotes_gpc())
        $val = stripslashes($val);
    return htmlspecialchars($val);
}
 
 
for($i = 0;$i < $_SESSION["rows"];$i++) {
 
    ?>
 
    <tr>
        <td>Name:</td>
        <td>          <input name="GROUPMEMBER_Name[]" value="<?php echo isset($P["GROUPMEMBER_Name"][$i])?strips($P["GROUPMEMBER_Name"][$i]):'' ?>">          </td>
 
        <td  >Sex:</td> <td width="10%">
 
              <select size="1" input name="GROUPMEMBER_Sex[]">
                <option <?php echo (isset($P["GROUPMEMBER_Sex"][$i])AND $P["GROUPMEMBER_Sex"][$i] == "Male")?' selected':'' ?>>Male</option>
                <option <?php echo (isset($P["GROUPMEMBER_Sex"][$i])AND $P["GROUPMEMBER_Sex"][$i] == "Female")?' selected':'' ?>>Female</option>
              </select>
              </td>
        <td width="5%">Age:</td>
        <td width="16%" >          <input name="GROUPMEMBER_Age[]" value="<?php echo isset($P["GROUPMEMBER_Age"][$i])?strips($P["GROUPMEMBER_Age"][$i]):'' ?>">          </td>
        <td width="7%"   >Height:</td>
 
<td width="12%">
 
          <select size="1" input name="GROUPMEMBER_Height[]" value="<?php echo isset($P["GROUPMEMBER_Height"][$i])?$P["GROUPMEMBER_Height"][$i]:'' ?>">
            <option <?php echo (isset($P["GROUPMEMBER_Height"][$i])AND $P["GROUPMEMBER_Height"][$i] == "None")?' selected':'' ?>>None</option>
            <option <?php echo (isset($P["GROUPMEMBER_Height"][$i])AND $P["GROUPMEMBER_Height"][$i] == '36"')?' selected':'' ?>>36"</option>
            <option <?php echo (isset($P["GROUPMEMBER_Height"][$i])AND $P["GROUPMEMBER_Height"][$i] == "3'7\"-4'10\"")?' selected':'' ?>>3'7"-4'10"</option>
            <option <?php echo (isset($P["GROUPMEMBER_Height"][$i])AND $P["GROUPMEMBER_Height"][$i] == "4'-11\"-5'5\"")?' selected':'' ?>>4'-11"-5'5"</option>
            <option <?php echo (isset($P["GROUPMEMBER_Height"][$i])AND $P["GROUPMEMBER_Height"][$i] == "5'-6\"-5'10\"")?' selected':'' ?>>5'-6"-5'10"</option>
            <option <?php echo (isset($P["GROUPMEMBER_Height"][$i])AND $P["GROUPMEMBER_Height"][$i] == "Over 5'10\"")?' selected':'' ?>>Over 5'10"</option>
          </select>          </font>     </td>
    <td width="6%"  >Bike Type:</td>
        <td width="15%"> <input name="GROUPMEMBER_biketype[]" value="<?php echo isset($P["GROUPMEMBER_biketype"][$i])? strips($P["GROUPMEMBER_biketype"][$i]):'' ?>">
 
</td>
</tr>
 
<?php
}
?>
<tr>
    <td colspan="2">&nbsp;
      <input name="SUBMIT" type="submit" value="Book"></td>
    <td width="4%">    </td>
</tr></table></table> </table>
    </form></div>
    <div id="maincontent">
  <div id="uppermaincontent"></div>
  <div id="lowermaincontent"></div>
  </div>
    <div id="footer">
        <div id="sitemap">
            <ul>
        <li><span class="sitemapheader"><a href="">Activities</a>
          </span>
          <ul>
              <li><span class="sitemapheader"><a href=""></a></span><a
 
href="">Cycle Hire</a></li>
              <li><a href="">Climbing</a></li>
                <li><a href="">Aerial Assault Course</a></li>
                <li><a href="">Traverse Wall</a></li>
                <li><a href="">Orienteering</a></li>
          </ul>
        </li>
        <li><a href="" class="sitemapheader">Book Online</a>        </li>
        <li><a href="" class="sitemapheader">Group Visits</a>
            <ul>
                <li><a href="">Schools</a></li>
                <li><a href="">Corporate/Teambuilding</a></li>
                <li><a href="">Parties</a></li>
            </ul>
        </li>
        <li><span class="sitemapheader"><a href="">Where To Find Us</a>
            </span>
          <ul>
              <li><span class="sitemapheader"><a href=""></a></span><a
 
href="">Whitwell</a></li>
              <li><a href="">Normanton</a></li>
                <li><a href="">Grafham</a></li>
          </ul>
        </li>
        <li><span class="sitemapheader"><a href="">Events</a>
            </span>
          <ul>
              <li><span class="sitemapheader"><a href=""></a></span><a
 
href="">Events Calendar</a></li>
              <li><a href="">Gallery</a></li>
          </ul>
        </li>
        <li><a href="" class="sitemapheader">Feedback</a>        </li>
    </ul>
        </div>
    </div>
    </div>
    <div id="bottombar"></div>
</div>
</body>
</html>

Re: Form + Group Members

Posted: Mon Feb 15, 2010 12:56 pm
by social_experiment
I tested the script on my localhost and got an error informing me that the mail cannot be sent, but that's not the fault of the script, i also received an error about headers that cannot be sent. Do you receive any errors?

Code: Select all

<?php $subject = "Subject";      
       $headers = 'From: '.$email . "\r\n" .
       'Reply-To: '.$email . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
        ini_set( 'sendmail_from', $email );
    
    unset($_SESSION["rows"]);
        
        $mail = mail($email, $subject, $message, $headers );
    if ($mail) {              
        header("Location:  bookingform.php");                 
                exit();
}?>
I added a 'subject' variable, and equated the mail string to a variable which is tested, if the mail is sent the you will be redirected. By moving 'unset($_SESSION['rows]) to outside the if loop, the headers is the first thing sent to the browser should the mail be sent and this removes the error message about the headers i got. Hope this helps.