[Register]
Powered by Elgg

Plugins :: Blog :: Need help with forms in plugins

February 22, 2007

I can't seem to get my head around this: I am trying to understand what the accepted way in elgg is to make a form, point it to some processing code, and redirect to some other page, with a message: "everything ok!".

I understand how to make the form using the template system. Everywhere in elgg there are these xxx_actions.php files. But the form action atribute  points sometimes to index.php, or is empty. How does the code in xxx_actions get executed? More to the point: is that still the way we should do things?

Posted by Ewout ter Haar @ Plugins


Comments

  1. If you're looking for the way to do things, ignore everything in /units/ - this is all code we're phasing out before version 1.0.

    Generally we're avoiding action at a distance these days, and posting back to a specific page. Pointing to an index.php is fine, or an actions.php might be neater. Then you want to:

    • Set $_SESSION['messages'] = $messages;
    • Redirect to the page of your choice
    • Stop execution here
    This will eliminate the "back button problem" of yore (i.e., avoid stuff being reposted), and allows for cleaner URLs. 

    user iconBen Werdmuller on Thursday, 22 February 2007, 13:09 UTC # |

  2. Ok, thanks Ben. That is what I did, but when I redirect to a users profile page, using

    [ocde=PHP]

    $_SESSION['messages'] = $messages;
        header("Location: " . redirect_url);
        exit;

    [/PHP]

    The messages are not shown. I checked the $_SESSION variable, and my message is there.  So now I have another question: how does one force the messages to get shown?

    user iconEwout ter Haar on Thursday, 22 February 2007, 13:15 UTC # |

  3. They should always show. Have you declared $messages to be global previous to that statement?

    user iconBen Werdmuller on Thursday, 22 February 2007, 13:18 UTC # |

  4. I just discovered that the messages show if I redirect the the home page or _/userdetails, but not when I redirect to a users page. I have the forwarder plugin installed, maybe that has something to do with it.

    user iconEwout ter Haar on Thursday, 22 February 2007, 13:25 UTC # |

  5. I'm pretty sure that's a bug with the forwarder plugin - I've just checked in an update that should solve the issue (by passing on the contents of $messages).

    user iconBen Werdmuller on Thursday, 22 February 2007, 13:30 UTC # |

  6. Yes!, thanks very much Ben.

    user iconEwout ter Haar on Thursday, 22 February 2007, 13:39 UTC # |

You must be logged in to post a comment.

Site supported by Curverider Ltd - powered by the awesome Elgg