WordPress.org

Ready to get started?Download WordPress

Forums

PHP/html form with mysql query (wordpress 3,5) (2 posts)

  1. vimes1984
    Member
    Posted 1 year ago #

    Here's my conundrum; to start of with I don't usually deal with PHP so excuse the ugly code.. I'm trying to retrive a list of WordPress user groups I've set up using: http://wordpress.org/extend/plugins/groups/ and give the user the ability to email each group indivually, using this plugin: http://wordpress.org/extend/plugins/email-users/ basiclly reproducing a listserv. Now after installing both plugins and setting up the list of groups the email plugin was showing the wordpress roles I.E editor/subscriber etc etc not my custom groups. so I've opened up the form that sends the group emails heres the orignal trunk: http://subversion.assembla.com/svn/rotarywebproject/trunk/wp-content/plugins/email-users-rwp/email_users_group_mail_form.php Now after hacking away at from line 97 to line 119 I've ended up with this:

    <select id="send_roles" name="send_roles[]" multiple="multiple" size="8" style="width: 654px; height: 250px;">
                <?php
                    $roles = mailusers_get_roles($user_ID, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META);
                    foreach ($roles as $key => $value) {
                ?>
    
    <?php
    $data = mysql_query("SELECT * FROM wp_groups_group")
    or die(mysql_error());
    while($info = mysql_fetch_array( $data )) 
    
    { ?>
    <option value="<?php echo $key; ?>" <?php
                        echo (in_array($key, $send_roles) ? ' selected="yes"' : '');?>>
                        <?php
                            printf('%s - %s', __('Group', MAILUSERS_I18N_DOMAIN), $info['name']);
     }
     ?>
            </option>
                <?php
                    }
                ?>
    </select>

    which is great it shows the email form now with my list of user groups the only problem is that no matter which email group I select it always sends the email to all the users in all the groups, after submitting the form the groups show up as all being selected instead of just the group i've chosen..... I'm banging my head against the wall with this so if anyone can help I'd be much appreciated!!! Kind regards Chris

  2. bcworkz
    Member
    Posted 1 year ago #

    What does the $send_roles array look like? It really doesn't make sense to use in_array() to control the output of selected="yes" since it should only occur once in the select group, so the == comparison to a single value makes more sense.

    If you really need multiple selections, a checkbox input list would make more sense.

Topic Closed

This topic has been closed to new replies.

About this Topic