SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need urgent help - PHP Form

    Hi,

    I created a select type list where a user can select multiple categories for their company. The values are then supposed to be mailed to me using the mail() function. The problem I'm having is that only the last selected value gets sent.

    Here is the link: http://www.foodsfortrade.com/database/add2.php. The select box at the bottom of the page is where I'm having troubles with. If multiple fields are selected, only the last field's value is sent through the e-mail.

    Any idea on how to get all the values from the selected fields to get mailed?

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2002
    Posts
    142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Darin
    Hi,

    I created a select type list where a user can select multiple categories for their company. The values are then supposed to be mailed to me using the mail() function. The problem I'm having is that only the last selected value gets sent.

    Here is the link: http://www.foodsfortrade.com/database/add2.php. The select box at the bottom of the page is where I'm having troubles with. If multiple fields are selected, only the last field's value is sent through the e-mail.

    Any idea on how to get all the values from the selected fields to get mailed?
    how are you storing the value(s) of this list? (comma separated list, array?)

    if the 'bottom' one is kept, it seems only 1 data point is being stored.

  3. #3
    Can we go to a 48 hour day?
    Join Date
    May 2002
    Location
    MI
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you need to add [] to the name of the field in the form. Then you will get all of the values in an array on the next page. You will have to loop through the values with a foreach or something to echo them all out into a string you can use to send you.
    mitechie.com
    "Techies just think a little differently
    ...at least that is what they keep telling me."

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Darin
    Hi,

    I created a select type list where a user can select multiple categories for their company. The values are then supposed to be mailed to me using the mail() function. The problem I'm having is that only the last selected value gets sent.

    Here is the link: http://www.foodsfortrade.com/database/add2.php. The select box at the bottom of the page is where I'm having troubles with. If multiple fields are selected, only the last field's value is sent through the e-mail.

    Any idea on how to get all the values from the selected fields to get mailed?
    This works:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
        <title>Get Select Values</title>
    </head>
    <body>
    <?php
    if(isset($_POST['Submit'])){
        if(isset(
    $_POST['list'])){
            foreach(
    $_POST['list'] as $item){
                echo 
    $item '<br>';
            }
        }
    }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
    <select name="list[]" size="3" multiple>
        <option value="1">list 1</option>
        <option value="2">list 2</option>
        <option value="3">list 3</option>
        <option value="4">list 4</option>
    </select>
    <input type="Submit" name="Submit" />
    </form>
    </body>
    </html>

  5. #5
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you peDey!

    That works great, but I need to put that variable in a mail() function so that I receive all the entries. When I put the $item variable in the e-mail, I once again receive only the last entry selected. Other than that, if I simply display the selected entries outside of a mail() function, they all show up correctly.

    Any idea on how to make it work?

    EDIT: I managed to get the $item variable in the e-mail, but what happens now is that I receive a seperate e-mail for each category selected. I want them all listed in one e-mail.
    Last edited by Darin; Apr 1, 2003 at 19:17.

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Darin
    Thank you peDey!

    That works great, but I need to put that variable in a mail() function so that I receive all the entries. When I put the $item variable in the e-mail, I once again receive only the last entry selected. Other than that, if I simply display the selected entries outside of a mail() function, they all show up correctly.

    Any idea on how to make it work?
    Well, I guess you need to loop through each array item (in a similar fashion to how I showed you above), and append it to your email message string.

  7. #7
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by peDey
    Well, I guess you need to loop through each array item (in a similar fashion to how I showed you above), and append it to your email message string.
    No idea how to do that, please see the EDIT in my previous message. Your help is greatly appreciated!

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Darin
    No idea how to do that, please see the EDIT in my previous message. Your help is greatly appreciated!
    Can you post your code?

  9. #9
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Darin
    No idea how to do that, please see the EDIT in my previous message. Your help is greatly appreciated!
    This should do it:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
        <title>Get Select Values</title>
    </head>
    <body>
    <?php
    if(isset($_POST['Submit'])){
        if(isset(
    $_POST['list'])){
            
    $msg ""// the email message that you will send
            
    foreach($_POST['list'] as $item){
                
    $msg .= $item "\n"//append the email message string
            
    }
            
    // Send email - NOTE: Update the email address to a valid email address
            
    mail("your_email@domain.com""Your Subject Here"$msg);
        }
    }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
    <select name="list[]" size="3" multiple>
        <option value="1">list 1</option>
        <option value="2">list 2</option>
        <option value="3">list 3</option>
        <option value="4">list 4</option>
    </select>
    <input type="Submit" name="Submit" />
    </form>
    </body>
    </html>


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
  •