how to set action to form in joomla modules

三世轮回 提交于 2019-12-22 18:31:53

问题


this is my file structure in my modules

tmpl
    default.php
helper.php
mod_helloword.php
mod_helloword.xml

i have this form in default.php file

<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

i want to pass it after click on submit to heper.php file in that form action attribute must set to what ??


回答1:


You don't need to set an action, you can simply give it a name. So you form would look something like this:

<form name="submit" method="post" enctype="multipart/form-data">
  <label for="file">Filename:</label>
  <input type="file" name="file" id="file"><br>
  <input type="submit" name="submit" value="Submit">
</form>

Then your helper.php :

class ModHelloWorldHelper {
    public static function submit($file) {
        // some code goes here
    }
}

Then your mod_helloworld.php (which calls the function in the helper.php):

$input = new JInput;
$post = $input->getArray($_POST);

if ($post["submit"]) {
    modHelloWorldHelper::submit($file);
}

Please note that you will of course have to make a few changes to suits your needs as the code above is just there to give you a small head start



来源:https://stackoverflow.com/questions/20659236/how-to-set-action-to-form-in-joomla-modules

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!