Adding dropdown to newthread
#1
I want to add a dropdown to the newthread template which I can do through a lugin. However, the thing I'm not sure about is recording the data entered from it.

I assume it must be one of the newthread hooks but which one? Also, I assume it will come through $mybb->input['var']?

Thanks in advanced
Reply
#2
Use newthread_start hook to build your drop down box. Find build_prefix_select( ) in /inc/functions.php to see how to style the dropdown to fit with the rest of MyBB. You can't use that code directly but you can learn from it.

Then put the template variable in the template where you want it to go.

It will be received by $mybb->input['<select input's name>'], then sanitize and use it
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#3
I thought so Smile thanks pavemen Smile
Reply
#4
i have written a plugin, it takes values from database added by admin and displays as dropdown.

i am using it as i have added a variable in my template :
<select name = 'response'>
$report_options
</select>

and i am using with hook
$plugins -> add_hook("report_start", "report_option");


function report_option() {

global $db , $templates , $report_options;
$query = $db->simple_select("report", "opt_id , opt_name , opt_display_name", "", array("order_by" => 'opt_name'));
$option = '';

if($db->num_rows($query) > 0)
{
while($value = $db->fetch_array($query))
{
$option.= '<option value="'.$value['opt_name'].'">'.$value['opt_name'].'</option>\n';
}
}
$report_options = $option;

}

may it helps you.
actually i am hiding report input box and showing the list , as per requirement.
With Regards and many thanks.
------------------------------------------
Reply
#5
One thing, how would I get it to display an error if the box is not filled? Similarly to how the yellow box appears if you submit without a subject Wink
Reply
#6
Just take a look at XThreads (or even use XThreads) - it includes exactly what you're looking for Wink
Reply
#7
Look at the inline_errors() function in functions.php.
Reply
#8
(2012-01-27, 01:39 PM)Jammerx2 Wrote: Look at the inline_errors() function in functions.php.

I tried that, I currently have this:
if ($display == 1)
		{
			if ($mybb->input['forumsubject'] == 0)
			{
			echo "STOP"; //to prove its incorrect
				inline_error("You must select a forum. If your problem does not relate to a specific forum, then select \"other\"");
				$mybb->input['action'] = "newthread";
			}
		}

Now, "STOP" is displayed, but the thread is still posted Confused
Reply
#9
add your validate code to the "datahandler_post_validate_post" hook and if the input is not set or is incorrect then

$this->set_error("you did not pick a forum");
return false;
Lost interest, sold my sites, will browse here once in a while. It's been fun.
Reply
#10
Would you mind giving me a code example of the function? I really can't get this to work.

My code:
function support_thread_validateforum(&$post)
	{
		global $mybb;
		$display = false;

       // print_r($post);
        //die();
		//get usergroups from settings
		$forumArr = explode(",","1,2");
		$groupArr = explode(",", "1,2");
		
		if (in_array($post['fid'],$forumArr))
		{
			//current forum is a support forum
			//is the user required to enter a forum?
			if (!in_array($mybb->user['usergroup'],$groupArr))
			{
				//this user isn't exempt
				$display = true;			
			}
			
		}
		
		if ($display == true)
		{
			if ($post['forumsubject'] == 0)
			{
			 set_error("you did not pick a forum");
             return false; 
			}
		}
		/*echo $display;
		print_r($mybb);
		print_r($mybb->input);
		die();*/
	}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)