Problem receiving Selection list values in aFormMail.php

Discussion in 'Customization & add-ons' started by Jenny, Apr 6, 2005.

  1. Jenny

    Jenny Guest

    Hi all,

    I added a checkbox and a selection list to my formMail something like this:

    ========
    <td>
    Option 1: <input type="checkbox" name="multi[]" value="option 1">
    Option 2: <input type="checkbox" name="multi[]" value="option 2">
    Option 3: <input type="checkbox" name="multi[]" value="option 3">
    </tr>
    <tr>
    <select name="multi2[]" size="3" multiple>
    <option>Option 1</option>
    <option>Option 2</option>
    <option>Option 3</option>
    <option>Option 4</option>
    <option>Option 5</option>
    </select>
    <tr>
    =============

    And I did make sure that I called the fields in the aFormMail.php as multi and multi2 (not multi[], multi2[]), but all I got from the autoreply mail is the word "Array"

    Do you have any idea why?
    Thanks in advantage,
    Jenny
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Jenny,
    unfortunately, we are unable to offer any support for aFormMail. It is a free script and is not supported.
  3. Jenny

    Jenny Guest

    thanks!

    :-(
    But thanks for replying!
    Jenny
  4. AaronC

    AaronC Guest

    Can you post or email the contents of your aformmail.php? Just the parts that you altered would be fine.
  5. Jenny

    Jenny Guest

    thanks AaronC!

    You can take a look at the form in here,
    the form

    I cannot post the complete php file in here, only the function:
    (if you want, you can download the formMail from this site)

    function get_form_data(){
    global $REQUEST_METHOD;
    global $HTTP_POST_VARS;
    global $HTTP_GET_VARS;

    $vars = ($REQUEST_METHOD == 'GET') ? $HTTP_GET_VARS : $HTTP_POST_VARS;
    //strip spaces from all fields
    foreach ($vars as $k=>$v) $vars[$k] = trim($v);
    return $vars;
    }


    Thanks again,
    Jenny
  6. AaronC

    AaronC Guest

    I'm not sure I understand what you have posted. If what you're trying to do is put the value that the user selects/checks in the autorespond email, just set the autorespond to look like this:

    $autoresponder_message = <<<MSG
    Hi %name_from%,

    Thank you for submitting the form, you big lug.<br>
    Here are the choices you made: $_POST['multi'] / $_POST['multi2']
    --
    MSG;

    Give that a try. If I've misinterpreted what you're trying to do, let me know. Nice images on the site btw.
  7. Jenny

    Jenny Guest

    the email!

    Hi AaronC,

    Sorry if I sounded confused. I'm trying to display the value of the selection list in both of the autoresponse and the email which is sent to me. All I got is the word "array" instead of the value of the selected items.

    You can view the php code in attached zip file.
    Thanks,
    Jenny
  8. AaronC

    AaronC Guest

    After reading the instructions more carefully, it appears my initial suggestion was incorrect. Substitute $POST_['select'] with %select%. As far as the email that gets back to you, the script should take care of that automatically. Let me know if this works.
  9. Jenny

    Jenny Guest

    still....

    Thanks for replying. I still got this:
    ===================
    Here is the information you have submitted:
    Array

    Thank you for submitting the form. We will contact you shortly.
    ---
    MSG;
    ===================

    BTW, thanks for comments on my pics :)
  10. AaronC

    AaronC Guest

    I checked out the form you posted earlier, but I didn't see a field with the name "select". Are you trying to get it to display the <select> object with the name "subject"? If so, you need to put %subject% in the autoresponse section. I would recommend not using labels that are already used for html tags anyways, as it adds confusion and possibly errors.
  11. Jenny

    Jenny Guest

    The form which I posted earlier has a selection list "Select one"
    I changed the name of the selection list field to "multi[]". But it still printed the word "Array". If I took out the "[]" it will print nothing.
    Thanks for your patience,
    Jenny
  12. AaronC

    AaronC Guest

    Ok, looking at this here:

    <select name="multi[]" size="3" multiple id="multi[]">
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
    </select>

    Your autoresponder variable should have %multi[]% somewhere in it. However, the bracket characters are generally used when a variable is an array (it holds multiple values). If you're unsure what a variable is, it's just a way of storing information for later use. For example:

    ------------------------------------------------------
    <script language="Javascript">
    {
    var age = prompt('How old are you');
    alert(answer);
    }
    </script>
    ------------------------------------------------------

    In this javascript snippet we've created a variable called age, and then displayed an alert that shows what the user entered. Feel free to cut and paste that into an html doc to see it in action.

    An array is just a way of storing multiple values in one variable. For example:

    ------------------------------------------------------
    var visitorInfo = new Array();
    visitorInfo[0] = prompt('How old are you?');
    visitorInfo[1] = prompt('What is your name?');
    visitorInfo[2] = prompt('Do you eat fromunda cheese');

    alert(visitorInfo[1] + ' is ' + visitorInfo[0] + ' years old.');
    ------------------------------------------------------


    So back to your code/markup. From the looks of what you have, it appears as though you're attempting to allow the user to select more than one entry from the list. From what you've told me, this doesn't seem to be the case, so use this:

    <select name="multi">
    <option>Option 1
    <option>Option 2
    <option>Option 3
    </select>

    And this in the autoresponder: %multi%

    I removed (id="multi[]") as it was causing a validation error because of the brackets and it's not needed for this script to run. If you're using javascript or stylesheets and you need to use the ID property, I would recommend not using the same value as you've used for the NAME property as it causes confusion and possibly errors. Also, the keyword "multiple" allows a selection of multiple entries.

    Let me know what works.
  13. Jenny

    Jenny Guest

    Thanks. It works! I feel like I've been bugging you forever! :) But now, what if users want to select more than one entry from the list? Something like this:
    ============
    <select name="xyz" size="3" >
    <option>Option 1
    <option>Option 2
    <option>Option 3
    </select>
    ============

    Really appreciated your times,
    Jenny
  14. AaronC

    AaronC Guest

    I'm glad I could help. For multiple selections, use the brackets like you had before "multi[]". This lets the script you've set to handle the form know that you've sent it an array and not just a single variable. Now normally in php form handling, you could access members of an array like so:
    -------------
    HTML:

    <form method=post action="phpscript.php">
    <select name="thingsYouLikeToDo[]" multiple>
    <option>Drink Jack Daniels
    <option>Borrow money from Grandma without paying her back
    <option>Write 'Return to sender' on your neighbor's mail
    <option>Snack on bulk candy in the grocery store
    </select>
    </form>

    PHP:

    <?php
    $badStuff = $_POST['thingsYouLikeToDo'];

    // Note that $thingsYouLikeToDo will be an array.

    print "Yer a bad dude! These are some of the things you do:";

    foreach ($badStuff as $temp) {
    print "$temp<br />";
    }
    ?>

    Now unfortunately I'm not sure how the formmail script you're using handles multiples. You may be able to get away with just putting the brackets & MULTIPLE keyword back into your HTML select tag, but most likely you're going to need to modify the script to do what you need.

    I can't be much more help to you as I don't have the time to devote to your project, but here are some additional resources to get you on your way:

    http://www.spsu.edu/cs/faculty/bbrown/papers/php2.html
    Talks about php and form handling

    htmlgoodies.com
    This site is a great resource for beginners and offers tutorials on almost all major web technologies including PHP

    Good luck!
  15. Jenny

    Jenny Guest

    Thank You!

    Thanks again AaronC for all the trouble you've gone through.
    I've checked the site you gave me, it seems very helpful. I might get something out of it.
    Best Regards,
    Jenny

Share This Page