www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need PHP HELP!!!!

  1. #1
    Join Date
    Jan 2003
    Posts
    411

    Question Need PHP HELP!!!!

    I have a select box that gets filled from a DB query and contains a list of email addresses. I allow the user to multi select email addresses and by way of javascript move the selected email addresses over to another select box.

    Now once they have their selected group of email addresses in the second box they hit submit and I process these email addresses. This is what I want.

    So how do I access these email addresses on the next page? I need all of the addresses from the second box that they moved over. I am using php on the server side and using the post method on the form. I tried accessing the select list via $HTTP_POST_VARS["editbox"] but it only lists one of the items. I thought that the post vars was setup like an array and I tried to access it like $HTTP_POST_VARS["editbox"][0] but this gave me the first letter of the one email address.


    Thank you for your time.

  2. #2
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    I think you need to change the name of the listbox to have square brackets on the end, i.e. "editbox[]". This should indicate to PHP to turn it into an array.

    Adam

  3. #3
    Join Date
    Jan 2003
    Posts
    411
    Thank you for the reply. You are the second person to suggest this so I think this is the right path.

    My problem is I am not very good with Javascript and when I change my code to have the "[]" after the name I assume I need to do the same where I reference it in my Javascript. Once I do this my what was working JS code to move the items from one list to the other stops working.

    Just for the heck of it I will post my code below...if you can (or have time) it would be great if you could point me in a direction as to how this name="editbox[]" effects my Javascript code or additional changes that need to be made so this array will work. The first edit box is populated by a MYSQL query (I spared you the query code, I tried to keep it short) I am excited that I am one step away from this working (it has been a week now). Again thank you for your time.

    My code :

    <script LANGUAGE=\"JavaScript\">



    <!--// -------------------------------------------------------------------
    // copySelectedOptions(select_object,select_object[,autosort(true/false)])
    // This function copies options between select boxes instead of
    // moving items. Duplicates in the target list are not allowed.
    // ------------------------------------------------------------------->
    function copySelectedOptions(from,to)
    {
    var options = new Object();
    for (var i=0; i<to.options.length; i++)
    {
    options[to.options[i].value] = to.options[i].text;
    }
    for (var i=0; i<from.options.length; i++)
    {
    var o = from.options[i];
    if (o.selected)
    {
    if (options[o.value] == null || options[o.value] == \"undefined\" || options[o.value]!=o.text)
    {
    to.options[to.options.length] = new Option( o.text, o.value, false, false);
    }
    }
    }
    if ((arguments.length<3) || (arguments[2]==true))
    {
    sortSelect(to);
    }
    from.selectedIndex = -1;
    to.selectedIndex = -1;
    }




    <!--// -------------------------------------------------------------------
    // removeSelectedOptions(select_object)
    // Remove all selected options from a list
    // (Thanks to Gene Ninestein)
    // ------------------------------------------------------------------->
    function removeSelectedOptions(from)
    {
    for (var i=(from.options.length-1); i>=0; i--)
    {
    var o=from.options[i];
    if (o.selected)
    {
    from.options[i] = null;
    }
    }
    from.selectedIndex = -1;
    }


    <!--this function is supposed to loop through and select all options on submit to post the vars I need.-->


    function White()
    {
    var opt = document.vblocked.towhite.options;
    var j, len = opt.length;
    for (j = 0; j < len; j++)
    {
    opt[j].selected = true;
    }
    return true;
    }


    </script>








    <!--***************************************END OF JS Functions****************************-->





    <table width=100% cellspacing=0 cellpadding=0 border=0>
    <tr>
    <td>
    <div><img src=../images/blocked_01.gif></div>
    </td>
    <td width=100%>
    <div><img src=../images/endline.gif></div>
    </td>
    </tr>
    </table><br><br>



    <form name=vblocked method=\"POST\" action=\"../admin/clearblocked.php\" onSubmit=\"return White()\">

    <!--******irrelevant body info************-->
    <table cellpadding=3 cellspacing=5 border=0>
    <tr>
    <td>
    All of the email addresses below have been sent an email
    of rejection that they must reply to for proof of legitimacy.
    Once they reply they will be added to SpamnIt's Database and
    be able to send you email. If you know someone in the list is
    legitimate or see a newsgroup/forum address,
    <b><a href=../admin/adminwhite.php>Click here</a></b> to add them to your
    Whitelist so you can immediately receive email from them.
    </td>
    </tr>
    <tr>
    <td>
    SpamnIt periodically cleans out these declined emails. If you would like
    to clear them sooner, check the <b>delete</b> box and click <b>Submit</b>
    to clear all declined email addresses from your list.<p>
    </td>
    </tr>
    </table>

    <table cellpadding=3 cellspacing=5 border=0>
    <tr>
    <td>
    <b>Email Address</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <b>Date Declined</b>
    </td>
    </tr>

    <!--******end of irrelevant body info************-->
    <tr>
    <td width=20>
    <select multiple name=blocked size=15 style=\"width:250;\">";

    //here we loop through our query results and build the list of
    //blocked email addresses and dates they were blocked.
    while ($row = @mysql_fetch_array($result))
    {
    //here we query the declined table inside this loop for each address
    //to see if they are still in there meaning they have not
    //replied to the email that was sent to them. We do this
    //so we can display a different row color to the user to
    //show who has replied after being blocked and who has not.
    $query = "select UserID from declined where EmailFrom ='".$row[1]."'";

    $result2 = @mysql_query($query);

    $row1 = @mysql_fetch_array($result2);

    if (!empty($row1[0]))
    {
    $value .='<Option style=color:red value ='.$row[1].'>'.$row[1]."&nbsp;&nbsp;&nbsp;".$row[2];
    }
    else
    {
    $value .='<Option value ='.$row[1].'>'.$row[1]."&nbsp;&nbsp;&nbsp;".$row[2];
    }
    }


    //here we run a query to count the total of declined emails for a user a display
    //them.
    $query = "select count(*) from blockedemails where UserID = ".$HTTP_SESSION_VARS["uid"];

    $result = mysql_query($query);

    $row = mysql_fetch_array($result);

    $value .= "</select>
    </td>
    <td>
    <a HREF=\"#\" onClick=\"copySelectedOptions(document.forms[0].blocked,document.forms[0].towhite,false);return false;\">Move to Whitelist&gt;&gt;</a><br><br>
    </td>
    <td>
    <select MULTIPLE NAME=\"towhite\" size=15 style=\"width:250;\">

    </select><br>
    <a HREF=\"#\" onClick=\"removeSelectedOptions(document.forms[0].towhite); return false;\">Remove Selected Options</a>
    </td>
    </tr>
    <tr>
    <td colspan=3>
    <span style=color:red>Emails in Red have not replied to the confirm email.</span>
    </td>
    </tr>
    <tr>
    <td>
    <b>Total Declined = ".$row[0]."</b>
    </td>
    <td colspan=2>
    <b>Clear Declined List <input type=checkbox name=\"clear\">&nbsp;&nbsp;&nbsp;<input type=\"submit\" name=\"submit\" value=Submit>
    </td>
    </tr>
    </table></form>
    <p><b><a href=../main/acctmain.php>Return to main account menu</a></b>";

  4. #4
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    This is a known problem. I'm afraid I don't have time to examine your code, but check out this article:

    http://www.php.net/manual/en/faq.htm...elect-multiple

    Adam

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles