MyBB Community Forums

Full Version: generate_submit_button(); Function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
Ok thanks, seems to work fine now! Smile

Last question (I promise Wink)

How can I create a log? So when an admin submits the form, it creates a log which says there username and all the details of what was submitted?

Cheers

Edit: Also how could I add the (intval($mybb->input['rec_comment'])) to only allow them to type in numbers in the text box?

This is the code:

/*receiving id*/  $addform_container->output_row($lang->add_rep_to_uid, "", $addform->generate_text_box('rec_uid', '', array('id' => 'rec_uid')), 'rec_uid');
/*uid giving*/	  $addform_container->output_row($lang->add_rep_from_uid, "", $addform->generate_text_box('from_uid', '', array('id' => 'from_uid')), 'from_uid');
/*PID of rep*/ 	  $addform_container->output_row($lang->add_rep_pid, "", $addform->generate_text_box('rec_post', '', array('id' => 'rec_post')), 'rec_post');
/*Amount of rep*/ $addform_container->output_row($lang->add_rep_amount, "", $addform->generate_text_box('rec_amount', '', array('id' => 'rec_amount')), 'rec_amount');
/*UNIX timestmp*/ $addform_container->output_row($lang->add_rep_unix, "", $addform->generate_text_box('unix_time', '', array('id' => 'unix_time',)), 'unix_time');
/*Rep Comment*/	  $addform_container->output_row($lang->add_rep_comment, "", $addform->generate_text_area('rec_comment', '', array('id' => 'rec_comment')), 'rec_comment');

			$addform_container->end();

			$rec_uid = $db->escape_string($mybb->input['rec_uid']);
			$from_uid = $db->escape_string($mybb->input['from_uid']);
			$rec_post = $db->escape_string($mybb->input['rec_post']);
			$rec_amount = $db->escape_string($mybb->input['rec_amount']);
			$unix_time = $db->escape_string($mybb->input['unix_time']);
			$rec_comment = $db->escape_string($mybb->input['rec_comment']);

Thanks a lot, Jammer Big Grin +Rep
Use intval instead of $db->escape_string and check to see if $rec_comment > 0, if not show an error saying you must enter a positive integer.
Thanks Jammer, the only problem is when I tested it, if I just used text, it'd show the error, however if I inputed something like this: 24jdej it'd still work. How could I show the error if any text is contained, or disallow text in certain textboxes altogether?

Cheers Smile
I guess you could use is_numeric() first and then intval it afterwards, but that would count hex values as numeric. You could also just have an array with 0-9 and check to see if there is anything other than that.
Thanks Jammer. Could someone give me an example of how to check to see if it's in the array?

I've created the array: $numbersarray = array("0","1","2","3","4","5","6","7","8","9");

How and where in the following code would I achieve this?
/*receiving id*/  $addform_container->output_row($lang->add_rep_to_uid, "", $addform->generate_text_box('rec_uid', '', array('id' => 'rec_uid')), 'rec_uid');
/*uid giving*/	  $addform_container->output_row($lang->add_rep_from_uid, "", $addform->generate_text_box('from_uid', '', array('id' => 'from_uid')), 'from_uid');
/*PID of rep*/ 	  $addform_container->output_row($lang->add_rep_pid, "", $addform->generate_text_box('rec_post', '', array('id' => 'rec_post')), 'rec_post');
/*Amount of rep*/ $addform_container->output_row($lang->add_rep_amount, "", $addform->generate_text_box('rec_amount', '', array('id' => 'rec_amount')), 'rec_amount');
/*UNIX timestmp*/ $addform_container->output_row($lang->add_rep_unix, "", $addform->generate_text_box('unix_time', '', array('id' => 'unix_time',)), 'unix_time');
/*Rep Comment*/	  $addform_container->output_row($lang->add_rep_comment, "", $addform->generate_text_area('rec_comment', '', array('id' => 'rec_comment')), 'rec_comment');
$numbersarray = array("0","1","2","3","4","5","6","7","8","9");
			$addform_container->end();
			$rec_uid = intval($mybb->input['rec_uid'], $numbersarray);
			$from_uid = intval($mybb->input['from_uid'], $numbersarray);
			$rec_post = intval($mybb->input['rec_post'], $numbersarray);
			$rec_amount = intval($mybb->input['rec_amount'], $numbersarray);
			$unix_time = intval($mybb->input['unix_time'], $numbersarray);
			$rec_comment = intval($mybb->input['rec_comment'], $numbersarray);

			$buttons = "";
			$buttons[] = $addform->generate_submit_button($lang->add_rep);
			$addform->output_submit_wrapper($buttons);
			$addform->end();
						if(!(empty($mybb->input['rec_uid'])) && (!empty($mybb->input['from_uid'])) && (!empty($mybb->input['rec_post'])) && (!empty($mybb->input['rec_amount'])) && (!empty($mybb->input['unix_time'])) && (!empty($mybb->input['rec_comment'])) && ($mybb->request_method == "post")){
				$db->query("INSERT INTO `".TABLE_PREFIX."reputation` VALUES (NULL, '$rec_uid', '$from_uid', '$rec_post', '$rec_amount', '$unix_time', '$rec_comment')");
			    flash_message("Reputation has been successfully added.", 'success');
			    admin_redirect('index.php?module=tools-easyrep');
			}
			elseif($mybb->request_method == "post"){
				flash_message("You must fill in all fields! Please go back and check if you've missed a field.", 'error');
				admin_redirect('index.php?module=tools-easyrep&action=addrep');
				die();
			}

Thanks again! Smile
I think you can use preg_match to verify the input instead of in_numeric (in this case). Also, to log all admin data there is a function, log_admin_action();.
Oh yeah, didn't think of that.

if(preg_match('/^\d+$/', $rec_comment))

I think that will work.
Thanks Omar & Jammer! It worked perfectly!

Regarding creating the log, could you let me know the markup for the log table and roughly how you create a) the log table and b) how you use log_admin_action();

Thanks so much guys Smile
You can just do log_admin_action(); or log_admin_action(array('do'=>'delete')); for extra data.
Thanks Omar,

It's logging as: tools-easyrep - (remove), how can I change the tools-easyrep ?

Thanks again Smile
Pages: 1 2 3 4 5