Irishnotsane
03-17-2023, 11:17 AM
Hi, I'm trying to create a form where users fill out a form to edit users vBCredits amount (Thinking they can see it by mistake) however upon submission it'll send them to rick roll as well as make a post within a specified thread from my userID letting me know who tried it and their form inputs
This is what I have so far but it doesn't work, any help would be appriciated.
I have a plugin with the hook "newpost_process"
if (!defined('VB_ENTRY')) {
die('Access denied.');
}
// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['username']) && !empty($_POST['give_or_take']) && !isset($_POST['threadid'])) {
// Redirect to rick roll
header('Location: https://www.youtube.com/watch?v=dQw4w9WgXcQ');
// Get the current user ID
global $vbulletin;
$userid = $vbulletin->userinfo['userid'];
// Get the form data
$username = htmlspecialchars_uni($_POST['username']);
$give_or_take = htmlspecialchars_uni($_POST['give_or_take']);
$tokens = intval($_POST['tokens']);
$reason = htmlspecialchars_uni($_POST['reason']);
// Create the post data array
$post_data = array(
'forumid' => 19, // The forum ID where the post will be created
'threadid' => 848094, // The thread ID where the post will be created
'parentid' => 0,
'username' => $vbulletin->userinfo['username'],
'userid' => $userid,
'title' => '',
'pagetext' => "Username: $username\nGive or Take: $give_or_take\nTokens: $tokens\nReason: $reason",
'iconid' => 0,
'attach' => '',
'posthash' => '',
'poststarttime' => TIMENOW,
'visible' => 1,
'moderated' => 0,
'subscribe' => 0,
'htmlstate' => '',
'allowsmilie'=> 1,
'showsignature' => 1,
'ipaddress' => $_SERVER['REMOTE_ADDR'],
'reportthreadid' => 0,
'postuserid' => $userid,
'isfirstpost' => 0
);
// Call the vB_DataManager_Post object to save the post
require_once(DIR . '/includes/class_dm.php');
require_once(DIR . '/includes/class_dm_threadpost.php');
$post_dm = new vB_DataManager_ThreadPost($vbulletin, ERRTYPE_SILENT);
$post_dm->set_info('skip_floodcheck', true);
$post_dm->set_info('is_automated', true);
$post_dm->set_existing($post_data);
$post_dm->pre_save();
if ($post_dm->errors) {
// Handle errors here
} else {
$post_dm->save();
}
}
and the form itself is
<div class="container1">
<div class="form-container">
<form action="newthread.php?do=postthread&f=19" method="post" onsubmit="return validateForm()">
<h1 class="custom">Administrators Token Adjustment Form</h1>
<div class="label-container">
<div class="form-field">
<label for="username">
<span>Username:</span>
</label>
<input type="text" id="username" name="username" placeholder="Enter recipient's Username" required>
</div>
<div class="form-field">
<label for="give_or_take">
<span>Do you want to give or take tokens?</span>
</label>
<div>
<label for="give"><input type="radio" id="give" name="give_or_take" value="give" required> Give</label>
<label for="take"><input type="radio" id="take" name="give_or_take" value="take" required> Take</label>
</div>
</div>
<div class="form-field">
<label for="tokens">
<span>Token Amount</span>
</label>
<input type="number" id="tokens" name="tokens" placeholder="Enter the number of tokens" min="0" max="25000" required>
</div>
<div class="form-field">
<label for="reason">
<span>Adjustment Reason (max 100 characters):</span>
</label>
<textarea id="reason" name="reason" placeholder="Enter the reason for the adjustment (max 100 characters)" maxlength="100" required></textarea>
</div>
<div class="button-container">
<button type="submit" onclick="validateForm(event)">Submit</button>
<button type="reset">Reset</button>
</div>
</div>
</form>
</div>
</div>
</body>
I can make the form simply redirect to rickroll upon submission, however I'm also wanting to see who has actually tried to do it, so I can name and shame them :)
(If you're interested in the form that just redirects, then see the code below - however it's only the above I need help with - so that it posts a reply to a specific thread using either a specific ID or the userID of the person who submitted the form (I don't mind either way, probs best for a specific ID though rather than theirs as long as it displays in the new post who submitted the form)
<!DOCTYPE html>
<html>
<head>
<title>Token Request Form</title>
<style>
.form-container {
flex: 1;
padding: 20px;
box-sizing: border-box;
flex-direction: row-reverse;
display: inline-flex;
flex-wrap: wrap;
align-content: flex-start;
flex-direction: row;
align-items: center;
font-family: Arial, sans-serif;
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
h1.custom {
text-align: center;
}
.label-container {
font-weight: bold;
margin-top: 10px;
display: flex;
width: 100%;
}
.label-container span {
margin-bottom: 5px;
}
input[type="text"], input[type="number"], textarea {
padding: 10px;
margin: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 16px;
width: 50%;
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
outline: none;
border-color: #008CBA;
}
input[type="number"] {
-webkit-appearance: none;
-moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
}
textarea {
height: 50px;
}
.button-container {
display: flex;
justify-content: center;
}
.button-container button[type="submit"] {
margin-right: 5px;
}
.error-message {
color: red;
font-size: 14px;
margin-top: 10px;
text-align: center;
}
.button-container button[type="submit"] {
margin-right: 5px;
background-color: #008CBA;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.button-container button[type="submit"]:hover {
background-color: #006B8F;
}
.button-container button[type="reset"] {
background-color: #ccc;
color: #000;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.container1 {
display: flex;
}
.form-container {
flex: 1;
padding: 20px;
box-sizing: border-box;
}
.label-container {
display: flex;
flex-direction: column;
}
.label-container > label {
margin-bottom: 10px;
}
.error {
border-color: red;
}
.button-container button[type="reset"]:hover {
background-color: #bbb;
}
.form-field {
display: flex;
flex-direction: column;
margin-bottom: 10px;
}
.form-field label {
margin-bottom: 5px;
}
#rightbox55 {
position: absolute;
right:20%;
}
@media screen and (max-width: 1200px) {
#rightbox55 {
position: inherit;
left:50%;
}
</style>
</head>
<body>
<div class="container1">
<div class="form-container">
<form onsubmit="return validateForm()">
<h1 class="custom"> Administrators Token Adjustment Form</h1>
<div class="label-container">
<div class="form-field">
<label for="username">
<span>Username:</span>
</label>
<input type="text" id="username" name="username" placeholder="Enter recipient's Username" required>
</div>
<div class="form-field">
</label>
<div class="form-field">
<label for="give_or_take">
<span>Do you want to give or take tokens?</span>
</label>
<div>
<label for="give"><input type="radio" id="give" name="give_or_take" value="give" required> Give</label>
<label for="take"><input type="radio" id="take" name="give_or_take" value="take" required> Take</label>
</div>
</div>
<div class="form-field">
<label for="tokens">
<span>Token Amount</span>
</label>
<input type="number" id="tokens" name="tokens" placeholder="Enter the number of tokens" min="0" max="25000" required>
</div>
<div class="form-field">
<label for="reason">
<span>Adjustment Reason (max 100 characters):</span>
</label>
<textarea id="reason" name="reason" placeholder="Enter the reason for the adjustment (max 100 characters)" maxlength="100" required></textarea>
</div>
<div class="button-container">
<button type="submit" onclick="validateForm(event)">Submit</button>
<button type="reset">Reset</button>
</div>
</div>
</form>
</div>
</div>
</body>
<script>
function validateForm(event) {
event.preventDefault();
const form = document.querySelector('form');
const inputs = form.querySelectorAll('input[required], textarea[required]');
let isFormValid = true;
inputs.forEach((input) => {
if (!input.value) {
input.classList.add('error');
isFormValid = false;
} else {
input.classList.remove('error');
}
});
if (!isFormValid) {
} else {
window.location.href = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
}
}
</script>
</body>
This is what I have so far but it doesn't work, any help would be appriciated.
I have a plugin with the hook "newpost_process"
if (!defined('VB_ENTRY')) {
die('Access denied.');
}
// Check if form is submitted
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['username']) && !empty($_POST['give_or_take']) && !isset($_POST['threadid'])) {
// Redirect to rick roll
header('Location: https://www.youtube.com/watch?v=dQw4w9WgXcQ');
// Get the current user ID
global $vbulletin;
$userid = $vbulletin->userinfo['userid'];
// Get the form data
$username = htmlspecialchars_uni($_POST['username']);
$give_or_take = htmlspecialchars_uni($_POST['give_or_take']);
$tokens = intval($_POST['tokens']);
$reason = htmlspecialchars_uni($_POST['reason']);
// Create the post data array
$post_data = array(
'forumid' => 19, // The forum ID where the post will be created
'threadid' => 848094, // The thread ID where the post will be created
'parentid' => 0,
'username' => $vbulletin->userinfo['username'],
'userid' => $userid,
'title' => '',
'pagetext' => "Username: $username\nGive or Take: $give_or_take\nTokens: $tokens\nReason: $reason",
'iconid' => 0,
'attach' => '',
'posthash' => '',
'poststarttime' => TIMENOW,
'visible' => 1,
'moderated' => 0,
'subscribe' => 0,
'htmlstate' => '',
'allowsmilie'=> 1,
'showsignature' => 1,
'ipaddress' => $_SERVER['REMOTE_ADDR'],
'reportthreadid' => 0,
'postuserid' => $userid,
'isfirstpost' => 0
);
// Call the vB_DataManager_Post object to save the post
require_once(DIR . '/includes/class_dm.php');
require_once(DIR . '/includes/class_dm_threadpost.php');
$post_dm = new vB_DataManager_ThreadPost($vbulletin, ERRTYPE_SILENT);
$post_dm->set_info('skip_floodcheck', true);
$post_dm->set_info('is_automated', true);
$post_dm->set_existing($post_data);
$post_dm->pre_save();
if ($post_dm->errors) {
// Handle errors here
} else {
$post_dm->save();
}
}
and the form itself is
<div class="container1">
<div class="form-container">
<form action="newthread.php?do=postthread&f=19" method="post" onsubmit="return validateForm()">
<h1 class="custom">Administrators Token Adjustment Form</h1>
<div class="label-container">
<div class="form-field">
<label for="username">
<span>Username:</span>
</label>
<input type="text" id="username" name="username" placeholder="Enter recipient's Username" required>
</div>
<div class="form-field">
<label for="give_or_take">
<span>Do you want to give or take tokens?</span>
</label>
<div>
<label for="give"><input type="radio" id="give" name="give_or_take" value="give" required> Give</label>
<label for="take"><input type="radio" id="take" name="give_or_take" value="take" required> Take</label>
</div>
</div>
<div class="form-field">
<label for="tokens">
<span>Token Amount</span>
</label>
<input type="number" id="tokens" name="tokens" placeholder="Enter the number of tokens" min="0" max="25000" required>
</div>
<div class="form-field">
<label for="reason">
<span>Adjustment Reason (max 100 characters):</span>
</label>
<textarea id="reason" name="reason" placeholder="Enter the reason for the adjustment (max 100 characters)" maxlength="100" required></textarea>
</div>
<div class="button-container">
<button type="submit" onclick="validateForm(event)">Submit</button>
<button type="reset">Reset</button>
</div>
</div>
</form>
</div>
</div>
</body>
I can make the form simply redirect to rickroll upon submission, however I'm also wanting to see who has actually tried to do it, so I can name and shame them :)
(If you're interested in the form that just redirects, then see the code below - however it's only the above I need help with - so that it posts a reply to a specific thread using either a specific ID or the userID of the person who submitted the form (I don't mind either way, probs best for a specific ID though rather than theirs as long as it displays in the new post who submitted the form)
<!DOCTYPE html>
<html>
<head>
<title>Token Request Form</title>
<style>
.form-container {
flex: 1;
padding: 20px;
box-sizing: border-box;
flex-direction: row-reverse;
display: inline-flex;
flex-wrap: wrap;
align-content: flex-start;
flex-direction: row;
align-items: center;
font-family: Arial, sans-serif;
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
h1.custom {
text-align: center;
}
.label-container {
font-weight: bold;
margin-top: 10px;
display: flex;
width: 100%;
}
.label-container span {
margin-bottom: 5px;
}
input[type="text"], input[type="number"], textarea {
padding: 10px;
margin: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 16px;
width: 50%;
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
outline: none;
border-color: #008CBA;
}
input[type="number"] {
-webkit-appearance: none;
-moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
}
textarea {
height: 50px;
}
.button-container {
display: flex;
justify-content: center;
}
.button-container button[type="submit"] {
margin-right: 5px;
}
.error-message {
color: red;
font-size: 14px;
margin-top: 10px;
text-align: center;
}
.button-container button[type="submit"] {
margin-right: 5px;
background-color: #008CBA;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.button-container button[type="submit"]:hover {
background-color: #006B8F;
}
.button-container button[type="reset"] {
background-color: #ccc;
color: #000;
border: none;
border-radius: 5px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.container1 {
display: flex;
}
.form-container {
flex: 1;
padding: 20px;
box-sizing: border-box;
}
.label-container {
display: flex;
flex-direction: column;
}
.label-container > label {
margin-bottom: 10px;
}
.error {
border-color: red;
}
.button-container button[type="reset"]:hover {
background-color: #bbb;
}
.form-field {
display: flex;
flex-direction: column;
margin-bottom: 10px;
}
.form-field label {
margin-bottom: 5px;
}
#rightbox55 {
position: absolute;
right:20%;
}
@media screen and (max-width: 1200px) {
#rightbox55 {
position: inherit;
left:50%;
}
</style>
</head>
<body>
<div class="container1">
<div class="form-container">
<form onsubmit="return validateForm()">
<h1 class="custom"> Administrators Token Adjustment Form</h1>
<div class="label-container">
<div class="form-field">
<label for="username">
<span>Username:</span>
</label>
<input type="text" id="username" name="username" placeholder="Enter recipient's Username" required>
</div>
<div class="form-field">
</label>
<div class="form-field">
<label for="give_or_take">
<span>Do you want to give or take tokens?</span>
</label>
<div>
<label for="give"><input type="radio" id="give" name="give_or_take" value="give" required> Give</label>
<label for="take"><input type="radio" id="take" name="give_or_take" value="take" required> Take</label>
</div>
</div>
<div class="form-field">
<label for="tokens">
<span>Token Amount</span>
</label>
<input type="number" id="tokens" name="tokens" placeholder="Enter the number of tokens" min="0" max="25000" required>
</div>
<div class="form-field">
<label for="reason">
<span>Adjustment Reason (max 100 characters):</span>
</label>
<textarea id="reason" name="reason" placeholder="Enter the reason for the adjustment (max 100 characters)" maxlength="100" required></textarea>
</div>
<div class="button-container">
<button type="submit" onclick="validateForm(event)">Submit</button>
<button type="reset">Reset</button>
</div>
</div>
</form>
</div>
</div>
</body>
<script>
function validateForm(event) {
event.preventDefault();
const form = document.querySelector('form');
const inputs = form.querySelectorAll('input[required], textarea[required]');
let isFormValid = true;
inputs.forEach((input) => {
if (!input.value) {
input.classList.add('error');
isFormValid = false;
} else {
input.classList.remove('error');
}
});
if (!isFormValid) {
} else {
window.location.href = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
}
}
</script>
</body>