generate_submit_button(); Function
#1
Hiya,

I'm trying to work on a plugin currently and was wondering how to do this:

I've generated a submit button, such as below:
$buttons[] = $form->generate_submit_button("Try");

I need to create a db query when the form is submitted.

How could I do this?
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#2
Check beforehand to see if $mybb->request_method == "post" to see if it's been submitted and then create the query using $db->query().
Reply
#3
Thanks Jammer

One other question, I'm using this following code:

$form_container->output_row("Comment", "", $form->generate_text_area('rec_comment', '', array('id' => 'rec_comment')), 'rec_comment');

to generate a text area, and the following code:

			if ($mybb->request_method == "post") {
				$db->query("INSERT INTO `table_name` VALUES (NULL, '{$mybb->settings['rec_uid']}', '{$mybb->settings['from_uid']}', '{$mybb->settings['rec_post']}', '{$mybb->settings['rec_amount']}', '{$mybb->settings['unix_time']}', '{$mybb->settings['rec_comment']}')");
			}

to check if the form has been submitted, and if it has, create the db query.

I need to grab the result from the text area (rec_comment) and that will be the value rec_comment in the db query.

Cheers Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#4
$mybb->input['rec_comment'] will have the contents of it. I also suggest escaping all of the settings that you insert along with the comment to prevent sql injection. This can be done by doing $db->escape_string($mybb->input['rec_comment']), along with the other settings you insert. I would also use $form->generate_hidden_field("my_post_key", $mybb->post_code) in your form and also check for verify_post_check($mybb->input['my_post_key']) when you check the request method.

Edit:
You'll only have to do the post key thing if you're creating your own page and not extending one that already has the check.
Reply
#5
Thanks Jammer Smile

I now have this:

if ($mybb->request_method == "post") {
				$db->query("INSERT INTO ".TABLE_PREFIX."reputation VALUES (NULL, '$mybb->input['rec_uid']', '$mybb->input['from_uid']', '$mybb->input['rec_post']', '$mybb->input['rec_amount']', '$mybb->input['unix_time']', '$mybb->input['rec_comment']')");
			}

I'm now getting an SQL error when I submit the form:


MyBB has experienced an internal SQL error and cannot continue.
SQL Error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rec_uid']', 'Array['from_uid']', 'Array['rec_post']', 'Array['rec_amount']', 'Ar' at line 1
Query:
INSERT INTO mybb_reputation VALUES (NULL, 'Array['rec_uid']', 'Array['from_uid']', 'Array['rec_post']', 'Array['rec_amount']', 'Array['unix_time']', 'Array['rec_comment']')

Cheers Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#6
This user has been denied support. This user has been denied support.
Make variables and make them added to database.

For example rather than adding $db->escape_string($mybb->input['rec_comment']), define it as variable like:

$rec_comment = $db->escape_string($mybb->input['rec_comment']);

and while adding it to table, just use $rec_comment variable, that should fix it.
Reply
#7
Change above code to;
if ($mybb->request_method == "post")
{
$db->query("INSERT INTO ".TABLE_PREFIX."reputation VALUES (NULL, $mybb->input['rec_uid'], $mybb->input['from_uid'], $mybb->input['rec_post'], $mybb->input['rec_amount'], $mybb->input['unix_time'], $mybb->input['rec_comment'])");
}
Reply
#8
Thanks guys - got it working perfectly now ! Big Grin

One other question (again Wink)

How do I add submenus like this:

http://i.imm.io/xyr1.png

Thanks again guys! Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply
#9
			$sub_tabs['active_tab'] = array(
			'title' => "Active Tab",
			'link' => "index.php",
			'description' => "Description"
		);
		$sub_tabs['other_tab'] = array(
			'title' => "Other Tab",
			'link' => "index.php"
		);
		$page->output_nav_tabs($sub_tabs, 'active_tab');

Add that after you output the header.
Reply
#10
How and where would I create the actions?

Cheers again, +rep all who have helped Smile
[Image: information.gif] MyBB Support Technician
Please do not PM me for support.


MyBBatically - A quick and easy way to update your board!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)