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
flash_message("The operation was successful.", 'success');

Replace 'success' with 'error' to do an error message.
Thanks Jammer, works perfectly! Smile

Regarding the field check for contents, I've tried the following code:

			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("Successfully added.", 'success');
			}
			else{
				flash_message("You must fill in all fields! Please go back and check if you've missed a field.", 'error');
				die();
			}

But it always displays the error message once it's submitted, even if all fields are not empty.

Cheers Smile
right after the flash_message();, redirect the user somewhere with the appropriate ACP function (can't remember the name).

flash_message(); messages are visible the next time the admin visits a page.
I've got this:

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');
			}
			else{
				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');
				die();
			}

It just keeps reloading the page now.

Cheers Smile
Probably you are redirecting to the same page Toungue? You need to redirect to another page, in case the message is "success" redirect to the ACP index, otherwise back the form page to fill the fields again, for example.
Make the else be elseif($mybb->request_method != "post").
Seems to be working now, cheers Big Grin

What would be the best way to check if a row exists?

I need to check if the value submitted matches one of these:

$db->query("DELETE FROM `".TABLE_PREFIX."reputation` WHERE rid='$rec_rid' OR uid='$rec_uid' OR adduid='$from_uid' OR pid='$rec_post' OR reputation='$rec_amount' OR dateline='$unix_time' OR comments='$rec_comment'");

for example, in the text box: $rec_comment, if it matches the comment in a row, execute the query.

This is my current code:

			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("DELETE FROM `".TABLE_PREFIX."reputation` WHERE rid='$rec_rid' OR uid='$rec_uid' OR adduid='$from_uid' OR pid='$rec_post' OR reputation='$rec_amount' OR dateline='$unix_time' OR comments='$rec_comment'");
			    flash_message("Reputation has been successfully deleted.", 'success');
			    admin_redirect('index.php?module=tools-easyrep');
			}
			elseif ((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")){
				flash_message("You must fill in at least one field! Please go back and check if you've missed a field.", 'error');
				admin_redirect('index.php?module=tools-easyrep');
				die();
			}
Cheers Smile
I'm not sure I completely understand, but is something like this what you want:
if(!$db->fetch_array($db->query("SELECT * FROM ".TABLE_PREFIX."reputation WHERE comments = '".$db->escape_string($rec_comment)."'")))
{
//query
}

Hopefully that's what you wanted. Make sure all of the user inputs are escaped if you haven't already.
Thanks Jammer. Smile

I have several text fields, such as this:

$addform_container->output_row($lang->add_rep_to_uid, "", $addform->generate_text_box('rec_uid', '', array('id' => 'rec_uid')), 'rec_uid');
	  

$addform_container->output_row($lang->add_rep_from_uid, "", $addform->generate_text_box('from_uid', '', array('id' => 'from_uid')), 'from_uid');

I am then creating a variable for each text box, then the users input is escaped, like this:

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

I'm using this at the end of the form:
			if ((!empty($mybb->input['rec_rid'])) || (!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("DELETE FROM `".TABLE_PREFIX."reputation` WHERE rid='$rec_rid' OR uid='$rec_uid' OR adduid='$from_uid' OR pid='$rec_post' OR reputation='$rec_amount' OR dateline='$unix_time' OR comments='$rec_comment'");
			    flash_message("Reputation has been successfully deleted.", 'success');
			    admin_redirect('index.php?module=tools-easyrep');
			}
			elseif ((empty($mybb->input['rec_rid'])) && (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")){
				flash_message("You must fill in at least one field! Please go back and check if you've missed a field.", 'error');
				admin_redirect('index.php?module=tools-easyrep&action=removerep');
				die();
			}

I'm using an OR statement in the query, which deletes the row if one or more of the users input is correct.

I'd need to check if the row exists with the conditions from the text fields, if it doesn't, I need it to display an error, however if it does, I need it to display that that row has been deleted and delete the row.

Sorry if it sounds a bit fragmented Wink

Cheers Jammer Smile
Well just replace the where part of the query with the one you use to delete.
Pages: 1 2 3 4 5