Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-17-2023, 11:17 AM
Irishnotsane Irishnotsane is offline
 
Join Date: Apr 2012
Posts: 64
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default April Fools form /Rickroll

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"

PHP Code:
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($vbulletinERRTYPE_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

HTML Code:
<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)


Code:
<!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>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:07 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03435 seconds
  • Memory Usage 2,229KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete