Date index for Oct 2003
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [achievo] Attach script to submit button
Hi,
Nele Vogel wrote:
1 and 2 work - thank you, Ivo! But how do I connect my script to the submit
button? Do I have to use the "dispatch_url" function?
No, here's how to do it:
Make sure, you're form has a action="dispatch.php" value, and method="post".
Then, also call session_form(SESSION_NESTED);
Now, add a hidden var called 'atkaction' and put some action name as
value in it. Then, implement this action in your atknode.
Hmm, not a clear explanation. Let me show you with some code:
<?php
class myCsvImporter extends atkNode
{
function myCsvImporter()
{
$this->atkNode("myCsvImporter");
}
function action_upload()
{
global $g_layout;
$g_layout->ui_top("this is the upload page");
$output = '<form action="dispatch.php" method="post">';
$output.= session_form(SESSION_NESTED);
$output.= '<input type="hidden" name="atkaction" value="import">';
.. (you're fileupload thingee here) ...
$output.= '<input type="submit" value="go">';
$output.= '</form>';
$g_layout->output($output);
$g_layout->ui_bottom();
}
function action_import()
{
$vars = $this->m_postvars;
// $vars contains, among other things, you're uploaded file.
// Check with var_dump($vars) how the structure is, so you can see
// what to parse
read_your_file_and_parse_csv($vars); // ;-)
// Now you have two options:
// $this->redirect(); this will make atk return to the previous
// screen (the upload sceen in this case)
// or:
// $g_layout->output('thanks for your input etc.');
}
}
?>
Now, from the menu, run action upload (using dispatch_url()). This will
present the upload box. Once the submit button is pressed, the system
will call action_import (because you told it to, using the atkaction
hidden value) and you can parse the contents.
Disclaimer: the above code is untested and will need some tweaking, but
you get the idea.
Greetings,
Ivo