• Resolved hiStrat76

    (@histrat76)


    Hello,
    Is it possible on the nomination form to have a logged in user be able to nominate another user and in addition choose the achievement he or she wants to nominate the user for from a dropdown list of all possible achievements, then click submit? This is a new plugin for me, so i’m not sure if I’m missing something in the shortcodes. The dropdown list of options would replace the text field.

    Thanks for your help,
    Anne

    https://www.ads-software.com/plugins/badgeos/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi Anne,

    This isn’t something we have out of the box, but theoretically should be possible to do if you’re dev-savy enough. There is the badgeos_get_nomination_form filter that will have the entire nomination form run through it, and you would be able to completely change the form that’s returned.

    I just filed an enhancement issue to have more data passed into that filter, but that may not be ready soon enough.

    Let me know if this is already “over your head” or if I should go into some more detail for you.

    Thread Starter hiStrat76

    (@histrat76)

    Thanks for the prompt response! I really appreciate it. I’ve worked a bit with filters and will see if I can get this working. Meanwhile, if you are willing to pass on any further detail that might be beneficial as I start working with this filter, that would be greatly appreciated.

    Anne

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    As is the form uses a hidden field that stores both the user ID and the achievement ID to award. The achievement ID is the one you provide originally with the shortcode. You’re going to need to find a way to provide a form field that will submit the ID of the achievement chosen by the user. Depending on how many achievements you want, that could be a fairly short <select> or it could be a pretty long list. As long as you can match up the form name attributes, the rest *should* fall in place if I recall correctly.

    The default markup/output can be found in the includes/submission-actions.php file at around line 1118, for reference and copy/pasting as necessary if you wish.

    Thread Starter hiStrat76

    (@histrat76)

    Hi Michael,

    I’m getting back to this many months later! Here is the modified form for the submission form I’m hoping to get working. It’s not properly submitting to the admin area, although the form itself looks alright. Any glaring changes I should make to make it work?:

    $sub_form = '<form class="badgeos-submission-form" method="post" enctype="multipart/form-data">';
    		// submission form heading
    		$sub_form .= '<legend>'. $args['heading'] .'</legend>';
    	   // nomination user
    		$sub_form .= '<label>'.__( 'User to nominate', 'badgeos' ).'</label>';
    		$sub_form .= '<p>' .wp_dropdown_users( array( 'name' => 'badgeos_nomination_user_id', 'echo' => '0' ) ). '</p>';
    		$sub_form .= '<fieldset class="badgeos-submission-content">';
    		$sub_form .= '<p><select multiple="multiple" name="badgeos-submission-content">
        <option id="760">Achievement 1</option>
        <option id="761">Achievement 2</option>
        <option id="762">Achievement 3</option>
        <option id="764">Achievement 4</option>
        <option id="765">Achievement 5</option>
        <option id="766">Achievement 6</option>
        <option id="767">Achievement 7</option>
        <option id="768">Achievement 8</option>
        <option id="769">Achievement 9</option>
        <option id="770">Achievement 10</option>
        <option id="771">Achievement 11</option>
        <option id="772">Achievement 12</option>
    </select></p>';
    		$sub_form .= '</fieldset>';
    		// submit button
    		$sub_form .= '<p class="badgeos-submission-submit"><input type="submit" name="badgeos_submission_submit" value="'. $args['submit'] .'" /></p>';
    		// hidden fields
    		$sub_form .= wp_nonce_field( 'badgeos_submission_form', 'submit_submission', true, false );
    		$sub_form .= '<input type="hidden" name="achievement_id" value="' . absint( $args['achievement_id'] ) . '">';
    		$sub_form .= '<input type="hidden" name="user_id" value="' . absint( $args['user_id'] ) . '">';
    	$sub_form .= '</form>';

    I’ve set the option id to be the specific achievement id.

    Thanks for any help you can give.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    What hook/filter are you using this with?

    Thread Starter hiStrat76

    (@histrat76)

    I was assuming I should use the badgeos_get_submission_form filter.

    My overall goal is to be able to send a form like this to certain users on our site so that they can nominate other users for achievements on the site and then allow for Admins to either approve or deny them before they officially publish to the nominated user’s profile. We’re using Buddypress. Is this a good approach? This is my first time using BadgeOS so I am very much open to suggestions on best approach.

    Thank you!
    Anne

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Ah yeah, I see my suggestion for that now in previous replies. Sorry for missing that ??

    From the looks of it, we call this function:

    function badgeos_save_submission_data() {
    
    	// If form items don't exist, bail.
    	if ( ! isset( $_POST['badgeos_submission_submit'] ) || ! isset( $_POST['badgeos_submission_content'] ) ) {
    		return;
    	}
    
    	// Nonce check for security
    	check_admin_referer( 'badgeos_submission_form', 'submit_submission' );
    
    	// Publish the submission
    	return badgeos_create_submission(
    		absint( $_POST['achievement_id'] ),
    		sprintf( '%1$s: %2$s', get_post_type( absint( $_POST['achievement_id'] ) ), get_the_title( absint( $_POST['achievement_id'] ) ) ),
    		esc_textarea( $_POST['badgeos_submission_content'] ),
    		absint( $_POST['user_id'] )
    	);
    }

    from within the output for the Submission form shortcode. However, it’s not going to match up as well with your version, so you will probably need to create your own callback on like the init action that checks for the form field values and acts appropriately afterwards. I’d mimic the function above a lot simply for the sake of having much of the code written already. I’d definitely consider changing the badgeos_submission_content field name, to prevent duplicate submissions from potentially occurring with badgeos_save_submission_data. However, that’s also going to cause issues with the “Submission saved successfully” output, exposing an area where our user-customization is not optimal.

    Hopefully this sort-of-rambling gives you some ideas. I have enhancement issues to file ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Allow users to select from a dropdown list of achievements on the nomination for’ is closed to new replies.