I'm new in joomla, I created a module for learning purpose, let name it mod_form1
, I don't know what framework or class in joomla i should use for this so I use plain HTML. this is my tmpl/default.php
code
<?php
// No direct access
defined('_JEXEC') or die; ?>
<?php echo '<br><b>'.$hello.'</b>';
//action file resides in "D:\XamppInstalation\htdocs\joomla\modules\mod_form1\tmpl"
//joomla component access = <yoursite>/joomla/index.php?option=com_<component_name>
$actionpath = '/'.basename(getcwd()).'/modules/mod_form1/tmpl/myaction.php';
echo '<br>actionpath - '.$actionpath;
echo '<br>basename() = '.basename(getcwd());
//echo '<br>current url = '. $_SERVER['REQUEST_URI'];
$currentURL = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo '<br>current url = '.$currentURL;
?>
<form name="indexForm1" method="post" action="<?php echo $actionpath ?> enctype="text/plain" accept-charset="UTF-8" target="_self" id="indexForm1">
<br>Your name <input type="text" id="indexEditbox1" name="name" value="<?php echo $actionpath ?>" spellcheck="false">
<br>Your Age<input type="text" id="indexEditbox2" name="age" value="" spellcheck="false">
<br><input type="submit" id="indexButton1" name="" value="Submit">
<br>using regular way to submit directly (form above) to bypass JOOMLA doesn't work,
<br>so use javascript instead to submit form directly to ACTION php file like form bellow.
</form>
<br><a href="<?php echo $actionpath ?>"><?php echo $actionpath ?></a>
<p>Enter some text in the fields below, then press the "Submit form" button to submit the form.</p>
<form id="myForm" method="post" action="<?php echo $actionpath ?>">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="hidden" name = "backurl" value="<?php echo $currentURL ?>">
<input type="button" onclick="myFunction()" value="Submit form">
</form>
<script>
function myFunction() {
document.getElementById("myForm").submit();
}
</script>
Script above use myaction.php
to take action to handle Form, button SUBMIT
seem doesn't work so I use javascript to do SUBMIT.
this is my 'tmpl/myaction.php`
<?php
echo '<br>form submitted';
echo '<br>MOD_FORM1 handled successfully';
$requestURL = $_POST['backurl'];
echo '<br>backURL = '.$requestURL;
?>
<script>
//setTimeout(function(){ window.location ="localhost"); }, 3000);
//setTimeout(function(){ alert("Hello"); }, 3000);
setTimeout(function(){ window.location = "http://<?php echo $requestURL ?>"; }, 3000);
//window.location = "https://www.example.com";
</script>
This module works as expected but I think it is not Good Practice because myaction.php
work outside Joomla environment. can anyone please show me the right way to create something similiar to my lame module above ?, what framework I should read ?
this is my entire module
com_ajax
instead of making own entry point docs.joomla.org/Using_Joomla_Ajax_Interface#Module_Support.