0

I am developing a plugin. I have one textbox. When I give some value in the textbox and click on "Save" button, the value of the textbox should be validated by sending a curl request. If it is not a valid value, then the plugin should not be saved and an error should be thrown. If the value is a valid one, only then it should be saved succesfully and the default message should popup "Plugin saved successfully".

Here is the link to my Code: https://codeshare.io/aYzgEE

Please check out the picture below, This is how my joomla plugin looks like. When I have empty textbox, An error message should be displayed. enter image description here

  • And what is your question? Please edit your post and make sure there is a clear question included in it. – FFrewin Apr 25 '17 at 8:24
  • Ok, and what have you tried so far? What research have you done? We're not here to do your homework or write all your code. Help us and we'll help you – Lodder Apr 25 '17 at 8:54
  • @FFrewin and Lodder I have updated the question. Please do check it and let me know. – Karthic Keyan Apr 25 '17 at 10:13
1

I think it's possible to implement, but it's very tricky. There is no system event triggered on plugin save. There is such events for content items - onContentBeforeSave, onContentAfterSave, but there is not for plugin options.

The tricky idea is to check with the URL if current action is your plugin save action. You'll not be able to interrupt it, but you'll be able to revert changes later. I'm able to create such methods, but have no ready solution.

So here is some code you can use as a reference.

Here is a fuctnion to check if the current action is plugin save action (works together with the construct method in this class, which sets some internal variables like $this->plg_full_name).

https://github.com/gruz/GJFields/blob/master/helper/plugin.php#L74

Next here I run the method

https://github.com/gruz/NotificationAry/blob/master/notificationary.php#L214

which sets a boolean flag.

And here if the plugin has been just saved a run a function

https://github.com/gruz/NotificationAry/blob/master/notificationary.php#L219

That function loads plugin options https://github.com/gruz/NotificationAry/blob/master/notificationary.php#L4249

So at that point you may get just saved options, check it with your methods and if something is wrong null the parameter and resave it to extensions table. And call a regular Joomla message saying something bad. Or even redirect to the plugin edit page.

Maybe you should better use some custom field with ajax to check the field on the fly before the plugin save. It would be better as for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.