- This topic has 3 replies, 2 voices, and was last updated 7 years, 8 months ago by
Steve.
-
AuthorPosts
-
-
May 28, 2014 at 6:05 pm #1762
achowellMemberHey I was wondering if you could add anything you want in the metaboxes? I had a couple of settings to update and change a table that was created from a plugin that I wanted to add to the edit page for my Custom Post Type, but for some reason the meta box that has all the code for it is just plain blank. Some of it is html, some of it PHP processing. If it’s a problem with my code, is there away debug it from there?
Thanks!
-
May 29, 2014 at 9:24 am #1766
-
May 29, 2014 at 10:39 am #1768
achowellMemberThanks Steve, I was able to get the meta box to display everything. But there still seems to be a problem. When I try to add a user in the form I created in this metabox to add to this specific project (an attendee table linking to the project ID the edit page is on), the POST method does not work. I know that GET works because I can use it for the ‘Remove Users’ links that are generated under the OPTIONS column of my table if there are attendees already in the database from user registration.
Here is the code and the main parts that are causing the problem are this part here –
<?php // Process add form if sent if(isset($_POST['mro_add_user'])) { $_POST = stripslashes_deep($_POST); $add_username = $_POST['mro_add_user']; if (username_exists($add_username) != NULL) { // Check not already registered $add_userid = username_exists($add_username); $extra_userdata = get_userdata($add_userid); $add_firstname = $extra_userdata->first_name; $add_lastname = $extra_userdata->last_name; $a_registered = $wpdb->get_var("SELECT user_id FROM ".$wpdb->prefix."mro_attendees WHERE event_id = ".$project_id." AND user_id = ".$add_userid); // If not already registered if ($a_registered == "") { $user_comment = $_POST['mro_add_comment']; $wpdb->insert($wpdb->prefix.'mro_attendees', array( 'event_id' => $project_id, 'user_id' => $add_userid, 'user_first_name' => $add_firstname, 'user_last_name' => $add_lastname, 'user_comment' => $user_comment ) ); ?> <div class="updated"><p><strong><?php _e('User ' . $add_username . ' added.' ); ?></strong></p></div> <?php } else { ?> <div class="updated"><p><strong><?php _e('User ' . $add_username . ' already on list.' ); ?></strong></p></div> <?php } } elseif(username_exists($add_username) == NULL) { ?> <div class="updated"><p><strong><?php _e('User ' . $add_username . ' not found.' ); ?></strong></p></div> <?php } } ?>Along with this –
<p style="clear:both;"> </p> <p style="clear:both;"><strong>Add Participant by wordpress username:</strong> </p> <form id="add_user" name="add_user" method="post" action="post.php?post=<?php echo $project_id; ?>&action=edit"> <p> <label for="mro_add_user"></label> Username<br /> <input name="mro_add_user" type="text" id="mro_add_user" size="40" maxlength="150" /> </p> <p>Comment<br /> <label for="mro_add_comment"></label> <input name="mro_add_comment" type="text" id="mro_add_comment" size="40" maxlength="40" /> </p> <p> <input type="submit" name="mro_add_user_submit" id="mro_add_user_submit" value="Add User" /> </p> </form>And this is the whole metabox for reference –
<?php /* Title: Attendee Information Post Type: mro_project Order: 3 */ ?> <?php $project_id = get_the_ID(); ?> <?php // Process add form if sent if(isset($_POST['mro_add_user'])) { $_POST = stripslashes_deep($_POST); $add_username = $_POST['mro_add_user']; if (username_exists($add_username) != NULL) { // Check not already registered $add_userid = username_exists($add_username); $extra_userdata = get_userdata($add_userid); $add_firstname = $extra_userdata->first_name; $add_lastname = $extra_userdata->last_name; $a_registered = $wpdb->get_var("SELECT user_id FROM ".$wpdb->prefix."mro_attendees WHERE event_id = ".$project_id." AND user_id = ".$add_userid); // If not already registered if ($a_registered == "") { $user_comment = $_POST['mro_add_comment']; $wpdb->insert($wpdb->prefix.'mro_attendees', array( 'event_id' => $project_id, 'user_id' => $add_userid, 'user_first_name' => $add_firstname, 'user_last_name' => $add_lastname, 'user_comment' => $user_comment ) ); ?> <div class="updated"><p><strong><?php _e('User ' . $add_username . ' added.' ); ?></strong></p></div> <?php } else { ?> <div class="updated"><p><strong><?php _e('User ' . $add_username . ' already on list.' ); ?></strong></p></div> <?php } } elseif(username_exists($add_username) == NULL) { ?> <div class="updated"><p><strong><?php _e('User ' . $add_username . ' not found.' ); ?></strong></p></div> <?php } } ?> <?php // Process remove if sent if (isset($_GET['remove_attendee'])) { $remove_attendee = (int)$_GET['remove_attendee']; } else { $remove_attendee = ''; } if ($remove_attendee != '') { $wpdb->query("DELETE FROM ".$wpdb->prefix."mro_attendees WHERE id = $remove_attendee"); $place = $_GET['place']; ?> <div class="updated"><p><strong><?php _e('Attendee '.$place.' removed.' ); ?></strong></p></div> <?php } ?> <h4>Event Participants:</h4> <p><table width="auto" border="0" align="left" cellpadding="5" cellspacing="5"> <tr> <th align="left" scope="col">Participant #</th> <th align="left" scope="col">Username</th> <th align="left" scope="col">First Name</th> <th align="left" scope="col">Last Name</th> <th align="left" scope="col">Email</th> <th align="left" scope="col">Comment</th> <th align="left" scope="col">Options</th> </tr> <?php $users = $wpdb->get_results("SELECT id, user_id, user_first_name, user_last_name, user_comment FROM ".$wpdb->prefix."mro_attendees WHERE event_id = ".$project_id." ORDER BY id ASC"); $num = 1; foreach ($users as $user) { $user_info = get_userdata($user->user_id); ?> <tr> <td><?php echo $num; ?></td> <td><?php echo $user_info->user_login; ?></td> <td><?php echo $user_info->first_name; ?></td> <td><?php echo $user_info->last_name; ?></td> <td><a href="mailto:<?php echo $user_info->user_email; ?>"><?php echo $user_info->user_email; ?></a></td> <td><?php echo $user_info->user_comment; ?></td> <td><a href="post.php?post=<?php echo $project_id; ?>&action=edit&remove_attendee=<?php echo $user->id; ?>&place=<?php echo $num; ?>">Remove User</a></td> </tr> <?php $num++; } ?> </table></p> <p style="clear:both;"> </p> <p style="clear:both;"><strong>Add Participant by wordpress username:</strong> </p> <form id="add_user" name="add_user" method="post" action="post.php?post=<?php echo $project_id; ?>&action=edit"> <p> <label for="mro_add_user"></label> Username<br /> <input name="mro_add_user" type="text" id="mro_add_user" size="40" maxlength="150" /> </p> <p>Comment<br /> <label for="mro_add_comment"></label> <input name="mro_add_comment" type="text" id="mro_add_comment" size="40" maxlength="40" /> </p> <p> <input type="submit" name="mro_add_user_submit" id="mro_add_user_submit" value="Add User" /> </p> </form> <p style="clear:both;"><strong>Participant Emails:</strong></p> <p>To keep the page simple, no mass emailer is included in this section. If you really want to email everyone you can copy the list below into your BCC to field and email them that way.</p> <blockquote> <p><?php $num = 1; foreach ($users as $user) { $user_info = get_userdata($user->user_id); echo $user_info->user_email . ", "; $num++; } ?></p> </blockquote> -
May 30, 2014 at 10:47 am #1773
SteveKeymasterUnfortunately, this is tough to test since I don’t have access to the custom db. Is
define('WP_DEBUG', true)?
-
-
AuthorPosts
- You must be logged in to reply to this topic.