I make a new form at user settings page (www.example.com/settings/user) and the form has been appeared succesfully. i use longtext form
but i don't understand why it's failed to save new setting ?
in start.php i put
elgg_register_plugin_hook_handler('usersettings:save', 'user', 'thespecialmessage');
and
function thespecialmessage($hook, $type, $value, $params)
{
$user_guid = (int) get_input('guid');
$new_message = get_input('specialmessage');
if($user = get_user($user_guid)){
elgg_set_plugin_user_setting('specialmessage',$new_message,$user->getGUID(), 'specialmessage');
if ($user->save()) {
elgg_register_plugin_hook_handler("forward", "system", "validate_specialmessage");system_message(elgg_echo('Your setting have been saved succesfully'));
}
}
}
there is no error when i click "save", but the new setting is not saved.
i'm sorry ,I have never made a plugin before , i just study the code form other plugin :)
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- iionly@iionly
iionly - 0 likes
- Avicena AlGhiffar Alsharaawy@AVicenaGhifa
Avicena AlGhiffar Alsharaawy - 0 likes
You must log in to post replies.You can't leave away the return statements. They are important for Elgg to know what it should do after executing the code of the function.
If you save the message using elgg_set_plugin_user_setting(), you don't need to use $user->save().
I don't know the idea you have for using elgg_register_plugin_hook_handler("forward", "system", "validate_specialmessage"); within the callback function but I'm pretty sure this won't work. Just add a separate function, e.g. named "validate_specialmessage" that does the validation of the message and call it directly.
elgg_echo() is used to be able to provide translations for the text you want to display - that is a good idea in the long run. So, add a language file to your plugin where you put the language strings into and then use elgg_echo() with the language string key you want to display. If you want to hard-code a text string that should be displayed, you can omit elgg_echo, e.g. system_message('My message') but it will be much harder to maintain if you ever want to change the text and you can't translate the output.
Without having tested I hope the following code is not too wrong:
And the language file (e.g. en.php):
Your answer is always detailed and useful :) Thank you very much for your code, i will try it :)