PHP Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rages4calm
Forum Newbie
Posts: 4
Joined: Fri Sep 10, 2004 11:16 am

PHP Form

Post by rages4calm »

http://www.slashingdesigns.com/maildivision.php
i have no clue what im doing wrong.. i don't want ppl to have to hold ctrl to choose more then one product and second off once you hit submit.. it only shows one product instead of all the ones u chose that entire file is the actual script.
http://www.slashingdesigns.com/maildivision.phps thats the script

So in example so you filled all that crap out well it shows u a copy of what is being emailed to me.. notice if u selected more then 1 item.. It only shows the last item you highlighted rather then all the ones you select.

So ya in conclusion I don't want ppl to have to hold ctrl to click I want them to be able to click and it hightlights and 2nd I want it to be able to show Everything on that 2nd page including what comes in my email.

*note I did not write this script got it from hotscripts website so my php knowledge is basic so please try to make it to where I can understand :-P*
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the code, since rages was too lazy to post it:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>MailDivision</title>
</head>
<body><center>
<table width="400" style="border:1px solid #000000;background-color:#9f9f9f;">
  <tr>
    <td bgcolor="#000000"> <p align="center"> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
        <?
function check_len(&$check, $field, $max, &$err_field, $err="", $min, $min_err="")
{
  if (strlen($field) > $max)
  {
     if ($err == "")
     {
       $err = $msg->err_maxlen($max);
     }
     $err_field = $err;
     if ($check==true) $check = false;
  }
  if (strlen($field) < $min)
  {
     if ($min_err == "")
     {
       $min_err = $msg->err_minlen($min);
     }
     $err_field = $min_err;
     if ($check==true) $check = false;
  }
}


function check_mail(&$check, $fld, &$error_field, $invalidchars="", $blanks="")
{

   global $msg;
   $expr = "^ї_\.0-9a-z-]+@(ї0-9a-z]ї0-9a-z-]+\.)+їa-z]їa-z]+\$";
   //echo "expr=" . $expr . "<br>";
   if ((!$fld) || ($fld=="") || (!eregi($expr,$fld)))
   {
     if ($invalidchars > "")
     {
      $error_field = $invalidchars . "<br>\n";
     } else {
      $error_field = "invalid characters<br>\n";
     }
     if ($check==true) $check =false;
   }
   if (strrpos($fld,' ') > 0)
   {
     if ($blanks > "")
     {
      $error_field = $blanks . "<br>\n";
     } else {
      $error_field = "blanks in e-mail<br>\n";
     }
     if ($check==true) $check =false;
   }
}

if (empty($HTTP_POST_VARSї"name"])) $HTTP_POST_VARSї"name"]="";
if (empty($err_name)) $err_name=" ";
if (empty($HTTP_POST_VARSї"email"])) $HTTP_POST_VARSї"email"]="";
if (empty($err_email)) $err_email=" ";
if (empty($HTTP_POST_VARSї"phone"])) $HTTP_POST_VARSї"phone"]="";
if (empty($err_phone)) $err_phone=" ";
if (empty($HTTP_POST_VARSї"address"])) $HTTP_POST_VARSї"address"]="";
if (empty($err_comment)) $err_address=" ";
if (empty($HTTP_POST_VARSї"product"])) $HTTP_POST_VARSї"product"]="13 Piece Complete Auto Care Bucket,Finish First Auto Polish,Finish Fast,Finish Prep Pre-Cleaner,LVR Protector,<br>
Metal Finish Polishing Cream,Engine Detail Kit,421 MPC,Finish First Wash & Conditioner,Liqui-Tech Wheels/Metal Protector,<br>
Window Finish Glass & Mirror,14 Piece Complete Cycle Care Bucket,Cycle Finish Engine Enhancer/Protector,Cycle Finish Polish,<br>
Cycle Spray Wash & Enhancer,Applicator Pad,3 Piece Starter Kit,5 Piece Cycle Kit,3 Piece Metal Kit,Aqua Dry";
if (empty($err_product)) $err_product=" ";

$checked = true;
if (isset($HTTP_POST_VARSї"submit"]))
{
  check_len($checked, $HTTP_POST_VARSї"name"],30,$err_name,"Field too long! Maximum:30",1,"Field required! Minimum:1");
  check_len($checked, $HTTP_POST_VARSї"email"],80,$err_email,"Field too long! Maximum:80",1,"Field required! Minimum:1");
check_mail($checked, $HTTP_POST_VARSї"email"], $err_email,"The e-mail contains invalid characters or is incomplete.", "The e-mail contains blanks.");
  check_len($checked, $HTTP_POST_VARSї"address"],300,$err_comment,"Field too long! Maximum:300",0,"Field required! Minimum:1");
  check_len($checked, $HTTP_POST_VARSї"products"],80,$err_products,"Field too long! Maximum:80",0,"Field required! Minimum:1");
}
if ( empty($HTTP_POST_VARSї"submit"]) or (!$checked) )
{
?>
        <br>
        Hold Down CTRL and click to choose more then one product to purchase.</font>
      <form action="<? echo $GLOBALSї"PHP_SELF"] ?>" method="post">
        <table cellpadding="4" border="0">
          <tr>
            <td valign="top"><font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">Name:</font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
              <input type="text" name="name" value="<? echo $HTTP_POST_VARSї"name"] ?>">
              </font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><? echo $err_name ?>
              </font></td>
          </tr>
          <tr>
            <td valign="top"><font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">Email:</font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
              <input type="text" name="email" value="<? echo $HTTP_POST_VARSї"email"] ?>">
              </font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><? echo $err_email ?>
              </font></td>
          </tr>
          <tr>
            <td height="32" valign="top"><font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">Phone:</font></td>
            <td><font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
              <input type="text" name="phone" value="<? echo $HTTP_POST_VARSї"phone"] ?>">
              </font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><? echo $err_phone ?>
              </font></td>
          </tr>
          <tr>
            <td valign="top"><font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">Address:</font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
              <textarea name="address"><? echo $HTTP_POST_VARSї"address"]?></textarea>
              </font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><? echo $err_address ?>
              </font></td>
          </tr>
          <tr>
            <td valign="top"><font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">Product:</font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
              <select name="product" size="22" multiple>
                <option value="    "> </option>
                <option value="13 Piece Complete Auto Care Bucket">13 Piece Complete
                Auto Care Bucket</option>
                <option value="Finish First Auto Polish">Finish First Auto Polish</option>
                <option value="Finish Fast">Finish Fast</option>
                <option value="Finish Prep Pre-Cleaner">Finish Prep Pre-Cleaner</option>
                <option value="LVR Protector">LVR Protector</option>
                <option value="Metal Finish Polishing Cream">Metal Finish Polishing
                Cream</option>
                <option value="Engine Detail Kit">Engine Detail Kit</option>
                <option value="421 MPC">421 MPC</option>
                <option value="Finish First Wash & Conditioner">Finish First
                Wash & Conditioner</option>
                <option value="Liqui-Tech Wheels/Metal Protector">Liqui-Tech Wheels/Metal
                Protector</option>
                <option value="Window Finish Glass & Mirror">Window Finish
                Glass & Mirror</option>
                <option value="14 Piece Complete Cycle Care Bucket">14 Piece Complete
                Cycle Care Bucket</option>
                <option value="Cycle Finish Engine Enhancer/Protector">Cycle Finish
                Engine Enhancer/Protector</option>
                <option value="Cycle Finish Polish">Cycle Finish Polish</option>
                <option value="Cycle Spray Wash & Enhancer">Cycle Spray Wash
                & Enhancer</option>
                <option value="Applicator Pad">Applicator Pad</option>
                <option value="3 Piece Starter Kit">3 Piece Starter Kit</option>
                <option value="5 Piece Cycle Kit">5 Piece Cycle Kit</option>
                <option value="3 Piece Metal Kit">3 Piece Metal Kit</option>
                <option value="Aqua Dry">Aqua Dry</option>
              </select>
              </font></td>
            <td> <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><? echo $err_product ?>
              </font></td>
          </tr>
          <tr>
            <td> </td>
            <td><font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
              <input type="submit" name="submit" value="Send">
              </font></td>
          </tr>
          <tr>
            <td colspan="2"> </td>
          </tr>
          <tr>
            <td colspan="2">  </td>
          </tr>
        </table>
      </form>
      <font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif">
      <?
  }
if (isset($HTTP_POST_VARSї"submit"]) and ($checked) ) {
  $msg = "<u>Thank You for Shopping with us. We will contact you soon.</u> \n";
  $msg .= "<b>name </b>:".$HTTP_POST_VARSї"name"]."\n";
  $msg .= "<b>email </b>:".$HTTP_POST_VARSї"email"]."\n";
  $msg .= "<b>phone </b>:".$HTTP_POST_VARSї"phone"]."\n";
  $msg .= "<b>address </b>:".$HTTP_POST_VARSї"address"]."\n";
  $msg .= "<b>product </b>:".$HTTP_POST_VARSї"product"]."\n";
  mail("carl@slashingdesigns.com","You have a new message",
$msg);
  echo "Message succesfuly sent to: <br><b><font color=red>Shine On It Sales Department</font></b><br>\n";
  echo nl2br($msg) . "<br>\r";
}
?></p>
      </font></td>
  </tr>
</table>
</body>
</html>
rages4calm
Forum Newbie
Posts: 4
Joined: Fri Sep 10, 2004 11:16 am

Post by rages4calm »

didn't know you could but thanks
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Another hint, you can do a websearch on PHP select multiple ;)

I'm pretty sure the found sites will advise you to use name="select[]" for example, and then you can walk through $_POST['select'];
rages4calm
Forum Newbie
Posts: 4
Joined: Fri Sep 10, 2004 11:16 am

Post by rages4calm »

timvw wrote:Another hint, you can do a websearch on PHP select multiple ;)

I'm pretty sure the found sites will advise you to use name="select[]" for example, and then you can walk through $_POST['select'];
already made it say products[] however now it shows as Products: array when i do a post
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

that is because it is an array....

foreach($_POST['products'] as $product) echo "$product <br>";
rages4calm
Forum Newbie
Posts: 4
Joined: Fri Sep 10, 2004 11:16 am

Post by rages4calm »

timvw wrote:that is because it is an array....

foreach($_POST['products'] as $product) echo "$product <br>";
I am sorry I am still extremely lost here.. I am new to php I think im psycho for even missing with it.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

probably you'll understand after reading [php_man]array[/php_man]
Post Reply