Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Is it possible to start a new discussion with pre-defined title and tag?
keefo
New
Something like
<a href="./vanillaboard/index.php?p=/post/discussion&title=VoteMe&tag=campaign">New Vote Post</a>
So I can put it into another webpage.
PS: version 2.0.18.8
2
Best Answer
-
hgtonight MVP
I can't think of any plugin that does anything similar. There are many different ways to approach this, but I would do the following:
- Clone my testing ground plugin (https://github.com/hgtonight/Vanilla-Plugins/tree/master/TestingGround)
- Put it in the
/plugins
folder - Enable it via the dashboard
- Start coding
- Restrict adding my resources (CSS and JSS) by changing the line
public function Base_Render_Before($Sender) {
topublic function PostController_Render_Before($Sender) {
- Find the differences in the
$Sender
variable between creating a new discussion and a new comment. I only want to add my resources on new discussions. - I modify my
PostController_Render_Before()
method to add the check// Only insert on new discussions if($Sender->RequestMethod == 'discussion') { $this->_AddResources($Sender); }
- Now that my resources are added, I need figure out a way to pre-populate the tags and discussion title. I am going to use JS.
- It sure would be nice to be able to change the title and tag in the link, so we need to add some definitions our JS can read. I add this right after
$this->_AddResources($Sender);
// Get the variables from the URL through the Request object provided by Garden $Request = $Sender->Request->Get(); // Sanitize the input to prevent some SQL injection attacks $Title = filter_var($Request['title'], FILTER_SANITIZE_ENCODED); $Tag = filter_var($Request['tag'], FILTER_SANITIZE_ENCODED); // Adding the variables as definitions will give our JS access to the filtered data $Sender->AddDefinition('TG_DiscussionTitle', $Title); $Sender->AddDefinition('TG_DiscussionTag', $Tag);
- Now that the data has been sanitized and is in a place easily accessible by JS, we can do the pre-population via JS. In
/plugins/TestingGround/js/testingground.js
place the following:// Get the wanted information from some definitions and return false if they don't exist var Title = gdn.definition('TG_DiscussionTitle', false); var Tag = gdn.definition('TG_DiscussionTag', false); // If the title or tag is missing we don't want to pre-populate if(!Title || !Tag) { return; } else { // We want to preset the values $('#Form_Name').val(Title); $('#Form_Tags').val(Tag); }
Now we have everything working how we want it. What is next? Well, whatever we want!
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
6
Answers
Welcome to the community!
Short answer is no. Long answer is yes with a plugin!
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Thanks @hgtonight, do you know any plugin? or I have to write my own plugin?
I can't think of any plugin that does anything similar. There are many different ways to approach this, but I would do the following:
/plugins
folderpublic function Base_Render_Before($Sender) {
topublic function PostController_Render_Before($Sender) {
$Sender
variable between creating a new discussion and a new comment. I only want to add my resources on new discussions.PostController_Render_Before()
method to add the check// Only insert on new discussions if($Sender->RequestMethod == 'discussion') { $this->_AddResources($Sender); }
$this->_AddResources($Sender);
// Get the variables from the URL through the Request object provided by Garden $Request = $Sender->Request->Get(); // Sanitize the input to prevent some SQL injection attacks $Title = filter_var($Request['title'], FILTER_SANITIZE_ENCODED); $Tag = filter_var($Request['tag'], FILTER_SANITIZE_ENCODED); // Adding the variables as definitions will give our JS access to the filtered data $Sender->AddDefinition('TG_DiscussionTitle', $Title); $Sender->AddDefinition('TG_DiscussionTag', $Tag);
/plugins/TestingGround/js/testingground.js
place the following:// Get the wanted information from some definitions and return false if they don't exist var Title = gdn.definition('TG_DiscussionTitle', false); var Tag = gdn.definition('TG_DiscussionTag', false); // If the title or tag is missing we don't want to pre-populate if(!Title || !Tag) { return; } else { // We want to preset the values $('#Form_Name').val(Title); $('#Form_Tags').val(Tag); }
Now we have everything working how we want it. What is next? Well, whatever we want!
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I got it works. @hgtonight
Hello. I am after the same thing. I have done exactly what @hgtonight has said and it did not work. Could I get a little heling hand please?
@prendo Welcome to the community!
What part are you getting stuck on?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I'm not exactly sure what part I did wrong. I downloaded all the files to your TestingGround and enabled it fine in the CP.
Here are my files after following your steps.
class.testingground.php
and
js/testingground.js
Ahh... I wasn't clear that you need to put your JavaScript code in the Dom ready function so it doesn't get executed until the page is ready.
So cut line 4 in your js file and paste it at the end of the file.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
My bad, thanks!