Main Stories
Slash Boxes

Slash Open Source Project

Slashcode Log In

Log In

[ Create a new account ]

Article Poll

Poll I found this article to be
Very Helpful
Not Helpful
Not Very Helpful
[ Results | Polls ]
Comments:0 | Votes:0

Usage of formkeys in plugins

posted by Krow on 11:17 AM April 17th, 2002   Printer-friendly   Email story
Hello again :),

I have just 'completed'(?!?) a little restructuring of the mailit2 plugin.
besides using templates for error-messages and sent-confirmation I included formkeys. My question is: is this the correct way?

(the code-formatting is a bit erroneous, though the best I could achieve by hand...)
  • fehlerhaft
  • Step 1: first invocation of the send-form
    if ( !$formkey && ($form->{op} eq "displayMailitForm")) {
       if(!formkeyHandler('generate_for mkey', $form->{name}, $formkey, \$message)){
            &n bsp;slashDisplay(...)
    If the formkey doesn't exist yet, I generate one and display the form.
  • Step 2.1: an error occured
    elsif( $form->{op} eq "mail" && (!$ok && !$ok2)){
       formkeyHandler('update_formkeyid ',$form->{name}, $formkey, \$message);
       # error handling
    I use 'update_formkeyid' to mark it as still valid, although the form was submitted.
  • Step 2.2: send the mail:
    elsif ($form->{op} eq "mail" &&
            ($ ok && $ok2) && $formkey &&
            ( !formkeyHandler('valid_check',$form->{name},$fo rmkey,\$message) &&
            &n bsp; !formkeyHandler('formkey_check',$form-&g t;{name},$formkey,\$message))) {
       # send the mail etc.
    I check the validity and previous usage of the key, without any further action to mark it as used, this is done automagically, isn't it?
Is this the correct way?
Though the plugin seems to function the way it should, I feel like asking you is the better way, as this is my first attempt to use slash (and perl...)
This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login
Loading... please wait.
  • I modelled it just like some of the other plugins that come with slash - ie message, journal, etc.

    Not all of them are the same, but they basically have the op loop at the beginning, and you have two subs for everything - one to display/edit the information, the other to save it.

    In the editdata, you check for state coming back from the $form data. If no state, it didn't exist before, so you


    then in your savedata sub, you'd do something like

      return unless _validFormkey();

    There's also formkey docs about this in docs/formkeys.txt. That took a bit of reading but I think I got the overall picture of how to do it from that, and looking at the plugins that the slash guys include in cvs.

    lottadot []
  • Well,
    As the comments in the plugin code mention, I am in the middle of adding formkeys and templates as you have done.
    Could you send me a copy of the code you have re-written?