0

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

1

2 Answers 2

0

Agree with @sharkey send your request via ajax the link above also has a link to a Demo module

You may also want to take a look at the below which shows how to use the JResponseJson which will be useful in returning a response and has some good examples that should help https://docs.joomla.org/JSON_Responses_with_JResponseJson

1
  • Rather than just referring people to the documentation, it is always more generous/helpful to demonstrate how to implement the necessary technique. If there is insufficient detail to provide this level of insight, please ask for greater detail from the OP. This means more effort from the asker and volunteers, but once a direct, reproducible script is on offer, future researchers will be very likely to benefit and upvote. Commented Sep 30, 2020 at 10:16
0

You can use the Radical Form plugin for your task.
This plugin I'm using on my client's websites because it is very useful.

Pros: you can create really any form: feedback form, questionnaire, survey, quiz, etc. Generate it by any serivice and save in Custom HTML Joomla module. This plugin is only a form handler.

Cons: This plugin is for professionals who are able to write the entire frontend of the form themselves: HTML and JS. The RadicalForm plugin has no appearance settings, layouts, or its own design. It only processes and sends form data. It supports its own plugins, which allows it to be used for API integration with various services, for example, CRM.

So, this approach allows you to show the users of the site forms that do not stand out from the overall design of the site, fully meet your requirements (because they are created entirely by you), the absence of spam.

3
  • Are you able to add more detail to this recommendation? Have you used it? What are the pros and cons of this extension? Are you affiliated with the extension? Commented Jun 22, 2022 at 13:01
  • I'm not affiliated with it and it's developer Commented Jul 14, 2022 at 7:24
  • Please edit your post instead of commenting. Commented Jul 14, 2022 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.