Skip to:

Re: Make your own custom BuddyPress page



I’d like to open this one back up. The project is for a local recycling program and I’m having trouble with a form for members to schedule pickups on the profile/index page. It calls XProfile address fields and tomorrow’s date for the default values, and should insert them into a custom table. The plugin creates a table and pulls the xprofile data fine, but nothing is reaching the database. I’ve tried every possible variation based on the bp-core and Travel-Junkie’s example above, but nothing is working.

Here’s the plugin:

Plugin Name: Collection Records
Plugin URI: -
Description: Adds a table and page for listing and editing Recylable Collections.
Version: 1.0

function collect_install_table() {
global $wpdb;
global $bp;

if ( !empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";

$table_name = $wpdb->prefix . 'collections';
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {

$sql = "CREATE TABLE " . $table_name . " (
sched_date datetime NOT NULL,
post_date datetime NOT NULL,
user_id bigint(20) UNSIGNED NOT NULL,
address_line_1 varchar(150) NOT NULL,
address_line_2 varchar(150) NOT NULL,
town varchar(150) NOT NULL,
state varchar(150) NOT NULL,
zip_code varchar(150) NOT NULL,
amount bigint(20) DEFAULT '0' NOT NULL,
verified tinyint(1) DEFAULT '1' NOT NULL,
paid tinyint(1) DEFAULT '1' NOT NULL,
KEY user_id (user_id)
) {$charset_collate};";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

/*Launch database*/

function bp_collections() {
global $wpdb;
global $bp;

/* bp_is_home() Checks to make sure the current user being viewed equals the logged in user */

if ( !bp_is_home() && !is_site_admin() )
return false;

/* Check for new information*/
if( isset($_POST['go'] ))
/* Check the nonce */

check_admin_referer( 'schedule_collect' );

if( $_POST['sched_date'] && ! $_POST['address_line_1'] || ! $_POST['sched_date'] && $_POST['address_line_1'] )
bp_core_add_message( __( 'We need a time and a place!', 'buddypress' ), 'error' );
$error = true;

if( ! $error )
$user_id = $bp->loggedin_user->id;

if( isset( $_POST['address_line_2'] ) ) {
$address_line_2 = $_POST['address_line_2'];

$result = $wpdb->query( $wpdb->prepare("
INSERT INTO $wpdb->1_collections
( sched_date, post_date, user_id, address_line_1, address_line_2, town, state, zip_code )
VALUES ( %s, %s, %d, %s, %s, %s, %s, %s )",
$_POST['sched_date'], $_POST['post_date'], $user_id, $_POST['address_line_1'], $address_line_2, $_POST['town'], $_POST['state'], $_POST['zip_code'] ) );

/* Set the feedback messages */
if ( $errors )
bp_core_add_message( __( 'There was a problem calling your pickup, please try again.', 'buddypress' ), 'error' );
bp_core_add_message( __( 'Thanks for calling a recycling pickup.', 'buddypress' ) );


bp_core_load_template( apply_filters( 'xprofile_template_display_profile', 'profile/index' ) );
/* Function to call xprofile Address label */

function collections_xprofile( $field ) {
echo bp_collections_get_member_list_xprofile_data( $field );
function bp_collections_get_member_list_xprofile_data( $field ) {
global $bp, $site_members_template;
return xprofile_get_field_data( $field, $site_members_template->member->id );


And the form:

<?php if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>

<form action="" method="post" id="oncall" class="oncall">

<label for="address">At</label>
<input type="text" name="address_line_1" id="address_line_1" value="<?php echo bp_collections_get_member_list_xprofile_data('Address Line 1') ?>" />
<input type="text" name="address_line_2" id="address_line_2" value="<?php echo bp_collections_get_member_list_xprofile_data('Address Line 2') ?>" />
<input type="text" name="town" id="town" value="<?php echo bp_collections_get_member_list_xprofile_data('Town') ?>" />
<input type="hidden" name="state" id="state" value="MS" />
<input type="" name="zip_code" id="zip_code" value="<?php echo bp_collections_get_member_list_xprofile_data('Zip Code') ?>" />
<br />
<label for="date">On</label>
<input type="text" name="sched_date" id="sched_date" value="<?php $tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y")); echo date("Y/m/d", $tomorrow); ?>" />

<input type="submit" name="go" id="go" value="go"/>
<input type="hidden" name="post_date" id="post_date" value="<?php $my_t=getdate(date("U")); print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]"); ?> " />

<?php wp_nonce_field( 'schedule_collect' ) ?>
<?php endwhile; endif; ?>

It has to be something simple but I’m lost. I’d really appreciate it if someone could take a minute and tell me what’s wrong with the code.

Skip to toolbar