50 users online (1 members and 49 guests)  


  Results 1 to 3 of 3

Related

  1. Form - checkboxes & file upload    Forum: PHP Forum
    Replies: 1
  2. Checkboxes and arrays    Forum: Javascript Forum
    Replies: 18
  3. Buttons and checkboxes    Forum: Javascript Forum
    Replies: 2
  4. Checkboxes on form = mailto recipients    Forum: CGI Perl Forum
    Replies: 1
  1. #1
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    php lists and checkboxes

    Thanks for all your previous replies to last posting - appreciated. However, just one thing. What do you do with lists and checkboxes? Can you use them at the beginning with like the following: What do you put in to make sure it returns all the options and shows which ones are checked/chosen?

    Code:
    $name=$_POST['name'];
    checkOK($name);
    $email=$_POST['email'];
    checkOK($email);
    $comments=$_POST['company'];
    checkOK($company);
    Regards

    HMC
    Last edited by vinyl-junkie; 05-24-2007 at 11:11 PM. Reason: Added code tags

  2. #2
    flann's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: I'm sorry to be a pain! But Help!

    I'm not sure I understand what you're asking about with checkboxes? It looks like you're working with textboxes?

    However if you want to see if a checkbox is checked you would use isset().

    $checkbox = (isset($_POST['checkboxname']) ? "checked" : "not checked";

    Also, what is in your checkOk() function?

  3. #3
    HMC's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: I'm sorry to be a pain! But Help!

    Hi flann,
    thanks for reply. So far I have the below
    but then after this (on the html form) there are several items to choose which can be either chosen by a 'list' option or by 'checkboxes' and I am not sure where this should be on the php code. If it helps the html. form is separate to the php code page.

    Code:
    <?php
    function checkOK($field)
    {
    if (eregi("\r",$field) || eregi("\n",$field)){
    die("Invalid Input!");
    }
    }
    $name=$_POST['name'];
    checkOK($name);
    $email=$_POST['email'];
    checkOK($email);
    $comments=$_POST['company'];
    checkOK($company);
    $comments=$_POST['address'];
    checkOK($address);
    $comments=$_POST['telno'];
    checkOK($telno);
    $comments=$_POST['message'];
    checkOK($message);
    $to="EMAIL REMOVED - Send PM to This User Instead";
    $message="$name just filled in your comments form. They said:\n$message\n\nTheir e-mail address was: $email";
    if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
    echo "Thank you for your enquiry, we will contact you shortly.";
    } else {
    echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
    }
       if ($_SERVER['REQUEST_METHOD'] != 'POST'){
          $me = $_SERVER['PHP_SELF'];
    } else {
          error_reporting(0);
       
       if(isset($_POST['submit'])) { 
       mail($to,$subject,$body,$headers);
       $to = ‘EMAIL REMOVED - Send PM to This User Instead';
          $address = stripslashes($_POST['address']);
       $subject = "contact message";
          $from = stripslashes($_POST['name']);
          $msg = "Message from: $from\n\n".stripslashes($_POST['message']);
         
         foreach($_POST ['check'] as $value){
         $check_msg = "Checked: $value\n";
         }
         $body = "From:$name_field\n Email:$email_field\n message:\n$check_msg";
    What I need to know is where and how do I place the code for the lists/checkboxes that people choose within the form.
    i.e., would it be

    Code:
    print_r ($_POST [checkbox']);
    Array
    (
    [checkbox] = Array
            (
         (0)= > checkboxname
         (1)= > checkboxname2
         )
    )
    How are lists done? or is the above incorrect? Many thanks hope it makes sense.

    HMC
    Last edited by vinyl-junkie; 05-24-2007 at 11:13 PM. Reason: Added code tags



Tags for this Thread