0

I created a custom html form module because I don't like using joomla extensions for forms etc. The reason is installing a new form extension requires me to learn about the extension all over and I find that annoying.

So here's my custom html form code:

<form action="HereYouGo.php" method="post">
   <center>
      <input type="text" name="fullname" placeholder="Full Name" size="25" required>
      <input type="text" name="email" placeholder="Email" size="25" required>
      <input type="password" name="psw" placeholder="Password" size="25" required>
   </center><br>
   <input type="submit" value="Here You Go!"/><br><br>
   <center>
      <h4>By clicking "Here You Go!" you agree with our terms & conditions and private policy.</h4>
   </center>
</form>

Anyone who can help me? Also which folder in joomla directory should I place my response PHP script.. In my case I'm specifically referring to "HereYouGo.php"

Help shall be greatly appreciated

Natalie Hedström
  • 2,607
  • 3
  • 25
  • 36
Kenny Kamei
  • 69
  • 1
  • 1
  • 11
  • This is not an answer to your question. But I just thought I should let you know that the `
    ` tag has been [deprecated](http://stackoverflow.com/questions/1798817/why-is-the-center-tag-deprecated-in-html). for a while now
    – Natalie Hedström Jun 08 '16 at 12:08
  • thanks for the update... it still works though – Kenny Kamei Jun 08 '16 at 12:36

2 Answers2

0

Why don't you create a module of type custom html and add the code there. Then publish the module wherever you need.

Omkar Frozen
  • 157
  • 9
  • What i mean is I already created "a module of type custom html" as u referred.. What I'm asking is where do I place the php code that will respond to the html form..Also I am using sourcerer plugin in joomla...Can I place the response php code there itself? – Kenny Kamei Jun 08 '16 at 12:41
  • don't go to tools->source code. Directly on text box that appears add {source} ALL your php code starting with {/source}. That should work for you. – Omkar Frozen Jun 08 '16 at 13:08
  • thank you...was thinking of that option too..will try as u said..thanks again – Kenny Kamei Jun 08 '16 at 17:01
0

First I would like to suggest that its better to create your own module or component then to use mod_html. mod_html was not meant for form submission. Anyways if still you want to proceed, then you can create a folder inside Joomla eg. "custom" and place the php file HereYouGo.php inside the folder. In your form replace HereYouGo.php by custom/HereYouGo.php. Assuming you have installed sourcer plugin. So your form looks like

{source}
<!-- You can place html anywhere within the source tags -->
<form action="custom/HereYouGo.php" method="post"><center><input name="fullname" required="" size="25" type="text" placeholder="Full Name" /> <input name="email" required="" size="25" type="text" placeholder="Email" /> <input name="psw" required="" size="25" type="password" placeholder="Password" /></center><br /> <input type="submit" value="Here You Go!" /><br /><br /><center>
<h4>By clicking "Here You Go!" you agree with our terms &amp; conditions and private policy.</h4>
</center>

<script language="javascript" type="text/javascript">
// You can place JavaScript like this

</script>
<?php echo JHtml::_( 'form.token' ); ?>
</form>
{/source}
JHtml::_( 'form.token' ) is to avoid CSRF Attack (Cross Site Request Forgery)

Now in your php just check the form token and then proceed what you want to do. Save in database etc. or redirect to another page. Typical php script should have these codes to work properly as it is an external script

    //Codes for accessing Joomla classes through external script
    define( '_JEXEC', 1 );
    define( 'JPATH_BASE', realpath(dirname(__FILE__).'/..' ));

    require_once ( JPATH_BASE. '/includes/defines.php' );
    require_once ( JPATH_BASE. '/includes/framework.php' );
    $mainframe = JFactory::getApplication('site');
    $mainframe->initialise();
 //Codes for accessing Joomla classes Ends
    $session = JFactory::getSession();
    $session->checkToken() or die( 'Invalid Token' ); //Check for form submission forgery
    // Instantiate the application.
    // Your code starts from here
    var_dump($_POST);
Amit Ray
  • 3,445
  • 2
  • 19
  • 35
  • I cant thank you enough Mr. Amit..You really took the time to explain all that..By the way, on a personal note, I'm located in India too..Thanks a million – Kenny Kamei Jun 08 '16 at 17:02
  • @KennyKamei You are most welcome. Also you can mark this as solved if your issue is resolved. – Amit Ray Jun 08 '16 at 17:11
  • well i did create my own module of the catergory "custom html" ...I then inserted my html form code into the module via sourcerer...I am not using mod_html extension if that's wat u mean...anyways Icant thank you enough Mr. Amit..You really took the time to explain all that..By the way, on a personal note, I'm located in India ..Thanks a million again – Kenny Kamei Jun 08 '16 at 17:22