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.
How to add notification after submitted the "Post Discussion", "Post Comment" buttons
luasoft
New
I'm writing a plugin, there, i have added a textbox in the New Discussion form.
for example:
public function PostController_AfterDiscussionFormOptions_Handler($Sender) { echo '<input type="text" name="Tag" id="Tag" >'; }
and then, i will check the data after submitted.
like this:
public function DiscussionModel_BeforeSaveDiscussion_Handler($Sender) { $Tag = $_REQUEST['Tag']; if ($this->IsValid($Tag)) { // insert into database } else { // show error message // $error = 'Tag is not empty'; } }
I want after submitted, my error message and default vanilla error message will be displayed together.
like this:
Body is required.
Category is required.
Name is required.
Tag is not empty <- my error message
How can i do that?
Thanks!
Tagged:
0
Comments
Easy:
But...
1.) Look at the DiscussionModel when the BeforeSave event is fired:
The values of the form are in
$Sender->EventArguments['FormPostValues']
and so you can reference your field as$Sender->EventArguments['FormPostValues']['Tag']
.2.) I don't know what your requirements are, but you can do some simple validations right out of the box (look at class.validation.php):
$Sender->Validation->ApplyRule('Tag', 'Required', T('Custom error message'));
If you leave out the custom error message, Vanilla shows the default "Tag is required."3.) You can also build your own custom "Rule":
great! that's what i need.
Thanks @R_J
You should really use the form object not hard code
This will ensure consistency.
grep is your friend.
also don’t do things like
There is was ways of checking to post if you, need to get the post value(s). Work with the framework.
grep is your friend.
but it's not working, got the error:
i used:
and it's ok.
thank you.
Most of the time $Sender is a Gdn_Controller, which has a form, but sometimes it is a Gdn_Model or something different.
In that case, you can always use Gdn::Controller() to get the current controller.
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
I think the problem is he used the form builder as a getter. The form builder was supposed to be used the the controller/view hook
PostController_AfterDiscussionFormOptions_Handler
, not for the post back.It is this line that is wrong
echo '<input type="text" name="Tag" id="Tag" >';
grep is your friend.