Results 1 to 11 of 11
  1. #1

    PHP Checkbox HELP

    Hello Everyone,

    I am a 2003 A.S. Web Graduate. I am trying to do a come back and i am having a hard time.

    I am working on a form and the php check box section is not working correctly. Idk y. When I hit submit and receive the email... it doesnt show nothing on the product section.

    This is my HTML format
    HTML Code:
    <form id="form1" name="form1" method="post" action="Sampleplastec2.php">
      <table width="600" border="0" cellspacing="2">
        <tr>
          <td><label for="Subject">Subject</label></td>
          <td><strong>
            <input type="text" name="Subject" id="Subject" />
          </strong></td>
        </tr>
        <tr>
          <td width="182"><label for="Nombre">Nombre</label></td>
          <td width="408"><strong>   
          <input type="text" name="Nombre" id="Nombre" />
          </strong></td>
        </tr>
        <tr>
          <td><label for="LastName">Apellido</label></td>
          <td>
          <input type="text" name="LastName" id="LastName" /></td>
        </tr>
        <tr>
          <td><label for="Company">Compañia/Empresa</label></td>
          <td>
          <input type="text" name="Company" id="Company" /></td>
        </tr>
        <tr>
          <td><label for="Email">Correo</label></td>
          <td>
          <input type="text" name="Email" id="Email" /></td>
        </tr>
        <tr>
          <td><label for="Phone">Télefono</label></td>
          <td>
          <input type="text" name="Phone" id="Phone" /></td>
        </tr>
        <tr>
          <td><label for="CityStateCountry">Ciudad, Estado, País</label></td>
          <td>
          <input type="text" name="CityStateCountry" id="CityStateCountry" /></td>
        </tr>
        <tr>
          <td>Productos</td>
          <td><input type="checkbox" name="Products[]" value="Progressive" />
          <label for="Progressive">Progressive</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="Slide" />
          <label for="Slide">Slide</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="HP" />
          <label for="HP">HP Products</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="Chempak" />
          <label for="Chempak">Chem-Pak</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="Congress" />
          <label for="Congress">Congress Tools</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="ITC" />
          <label for="ITC">ITC</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="Desecante" />
          <label for="Desecante">Desecante</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="Bunting" />
          <label for="Bunting">Bunting</label></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input type="checkbox" name="Products[]" value="Diversified" />
          <label for="Diversified">Diversified</label></td>
        </tr>
        <tr>
          <td><label for="Message">Comentarios</label></td>
          <td>
          <textarea name="Notes" id="Notes" cols="45" rows="5"></textarea></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><label for="Submit"></label>
          <input type="submit" name="Submit" id="Submit" value="Submit" /></td>
        </tr>
      </table>
    </form>
    And This is my PHP Section
    PHP Code:
    <?
    $subject
    ="$Subject";
            
    $message .= "Name: ";
    $message .= "$Nombre\r\n";

    $message .= "Last Name: ";
    $message .= "$LastName\r\n";

    $message .= "Company: ";
    $message .= "$Company\r\n";
      
    $message .= "E-Mail: ";
    $message .= "$Email\r\n";
      
    $message .= "Phone: ";
    $message .= "$Phone\r\n";
      
    $message .= "City, Sate, Country: ";
    $message .= "$CityStateCountry\r\n";

    /*checkbox*/  
    $message .= "Products: ";
    $Message .= $checkbox=$_Post['Products'];
            
    $message .= "Comments: ";
    $message .= "$Notes\r\n";
            
    $mail_form="$Email";
            
    $header="from: $Nombre <$Email>";

    /*Send the email*/        
    $to =[email protected]';
            
    $send_contact=mail($to,$subject,$message,$header);
            
          if(
    $send_contact){
            echo 
    "We've received your information"; }
        else{
            echo 
    "ERROR";
        }
    ?>

  2. #2
    Join Date
    Nov 2009
    Location
    USA
    Posts
    674
    This works for me
    php code:
    <?

    foreach($_REQUEST as $name => $value) { //set the variables in the registry
    if (!is_array($value)) {
    $value = stripslashes($value);
    }
    $$name = $value;
    }

    $subject="$Subject";

    $message .= "Name: ";
    $message .= "$Nombre\r\n";

    $message .= "Last Name: ";
    $message .= "$LastName\r\n";

    $message .= "Company: ";
    $message .= "$Company\r\n";

    $message .= "E-Mail: ";
    $message .= "$Email\r\n";

    $message .= "Phone: ";
    $message .= "$Phone\r\n";

    $message .= "City, Sate, Country: ";
    $message .= "$CityStateCountry\r\n";

    /*checkbox*/

    $strExpert="";
    $count=count($Products);
    for($i=0;$i<$count;$i++) {
    $strExpert .= $Products[$i] . ", ";
    }

    $message .= "Products: ";
    $message .= $strExpert . "\n";

    $message .= "Comments: ";
    $message .= "$Notes\r\n";

    $mail_form="$Email";

    $header="from: $Nombre <$Email>";

    /*Send the email*/
    $to [email protected]';


    $send_contact=mail($to,$subject,$message,$header);

    if($send_contact){
    echo "We've received your information"; }
    else{
    echo "ERROR";
    }
    ?>

    Mark

  3. #3
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,381
    $_POST['products'] is not going to contain a string. It will be an array. So something like

    PHP Code:
    $message .= "Products: ";
    foreach(
    $_POST['Products'] as $product) {
      
    $message .= $product ', ';

    should work.

    Also, remember that CapiTalizaTioN matters. $message != $Message

  4. #4
    This told me error on line 14

  5. #5
    Actually I got an error after I click submit but I just received the email I finally got it to show.

    Now y am i getting the error after submit

  6. #6
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,381
    We need to see all of your code and know the exact error in order to help you.

  7. #7
    ThatSciptguy

    after i submit on the form i get the following error:

    Warning: Invalid argument supplied for foreach() in Sampleplastec2.php on line 11
    We've received your information

    But I still received the email with everything working.

    I used the html code that i posted n the php you posted.

    BTW thank you for your help. I am a little confused right about now

  8. #8
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,381
    You can place error_reporting(0) at the top of your file to hide the warning (Not recommended) or you can check that $_POST['products'] is actually an array before looping over it (if(is_array($_POST['products'])) etc...)

  9. #9
    This is the php code i am using
    <?

    foreach($_REQUEST as $name => $value) { //set the variables in the registry
    if (!is_array($value)) {
    $value = stripslashes($value);
    }
    $$name = $value;
    }

    $subject="$Subject";

    $message .= "Name: ";
    $message .= "$Nombre\r\n";

    $message .= "Last Name: ";
    $message .= "$LastName\r\n";

    $message .= "Company: ";
    $message .= "$Company\r\n";

    $message .= "E-Mail: ";
    $message .= "$Email\r\n";

    $message .= "Phone: ";
    $message .= "$Phone\r\n";

    $message .= "City, Sate, Country: ";
    $message .= "$CityStateCountry\r\n";

    /*checkbox*/

    $strExpert="";
    $count=count($Products);
    for($i=0;$i<$count;$i++) {
    $strExpert .= $Products[$i] . ", ";
    }

    $message .= "Products: ";
    $message .= $strExpert . "\n";

    $message .= "Comments: ";
    $message .= "$Notes\r\n";

    $mail_form="$Email";

    $header="from: $Nombre <$Email>";

    /*Send the email*/
    $to [email protected]';


    $send_contact=mail($to,$subject,$message,$header);

    if($send_contact){
    echo "We've received your information"; }
    else{
    echo "ERROR";
    }
    ?>

  10. #10
    I just wanted to say thank you I remove this section

    foreach($_REQUEST as $name => $value) { //set the variables in the registry
    if (!is_array($value)) {
    $value = stripslashes($value);
    }
    $$name = $value;
    }
    And its work perfectly. Thank you so much i have been bumping heads with this for 2 days now.

  11. #11
    Join Date
    May 2009
    Posts
    766
    Quote Originally Posted by Lilmamaisa View Post
    This is the php code i am using

    PHP Code:
    $strExpert="";
    $count=count($Products);
    for(
    $i=0;$i<$count;$i++) {
    $strExpert .= $Products[$i] . ", ";
    }

    $message .= "Products: "
    $message .= $strExpert "\n"
    Or simply...

    PHP Code:
    $message .= "Products: " implode(", "$Products); 

Similar Threads

  1. PHP: Playing with CheckBox ?
    By 10gbus in forum Programming Discussion
    Replies: 2
    Last Post: 09-22-2009, 01:21 PM
  2. JS set checkbox by select value?
    By tjphippen in forum Programming Discussion
    Replies: 5
    Last Post: 05-24-2009, 07:21 PM
  3. Custom Checkbox Script - Need help!
    By Conica in forum Programming Discussion
    Replies: 2
    Last Post: 09-12-2007, 01:50 PM
  4. Checkbox Validation
    By samnite in forum Programming Discussion
    Replies: 3
    Last Post: 07-07-2005, 08:36 PM
  5. Help! Php Checkbox Question
    By spinyalatis in forum Programming Discussion
    Replies: 9
    Last Post: 04-11-2003, 04:42 AM

Posting Permissions

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