1

I'm trying to make a simple contact form but I can't pass params from my module to external action="contact.php" file.


This is how I'm trying to get parameters to an external file:

$app = JFactory::getApplication('site');
$app->initialise();

$session = JFactory::getSession();

jimport( 'joomla.application.module.helper' );

$db = JFactory::getDBO();
$db->setQuery("SELECT params FROM #__modules WHERE module = 'mod_my_contact_form'");

$module = $db->loadObject();
$params = new JRegistry($module->params);

$contact_email = $params->get('myemail');

Result of the print_r('My e-mail: ' . $contact_email); stays empty:

My e-mail:


What might be the cause of this issue?


EDIT: I've tried that method but without any results:

$app = JFactory::getApplication('site');
$app->initialise();

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_my_contact_form');

$registry = new JRegistry();
$params = $registry->loadString($module->params);

$contact_email = $params->get('myemail');

EDIT 2:

File structure:

mod_my_contact_form/
    tmpl/
       includes/
            contact.php
       default.php
     helper.php
     mod_my_contact_form.php
     mod_my_contact_form.xml

EDIT 3: I think the xml is built properly. This is how looks the param part:

...
    ...
    <fieldset name="contact_form" label="Contact Form">
        <field name="myemail" type="email" label="JGLOBAL_EMAIL" description="E-mail where you will receive all messages" size="30" class="inputbox" validate="email" />
    </fieldset>
   </fields>
  </config>
</extension>
  • Where is your file contact.php file ?? Can you show the file structure ? – Sudhir Sapkal May 22 '18 at 11:31
  • Your second code snippet should work seems you have something wrong in your xml file(manifest xml) – Sudhir Sapkal May 22 '18 at 12:44
2

By looking at updated xml file, I see only one issue that you haven't used <fields name="params"></fields> in config tag and hence your modparams object showing blank. Try below xml snippet for configs and check one more time the $module->params values.

<config>
<fields name="params">
<fieldset name="contact_form" label="Contact Form">
<field name="myemail" type="email" label="JGLOBAL_EMAIL" description="E-mail where you will receive all messages" size="30" class="inputbox" validate="email" />
</fieldset>
</fields>
</config>

Hope this will solve your problem :)

EDIT : By Looking at your comment I tried my self to develop module.Below are the steps -

  1. I followed file structure given in question.
  2. Here is My xml(mod_my_contact_form.xml)

    <?xml version="1.0" encoding="utf-8"?> <extension version="3.0" type="module" client ="site" method="upgrade"> <name>mod_my_contact_form</name> <files> <filename module="mod_my_contact_form">mod_my_contact_form.php</filename> <filename>index.html</filename> <folder>tmpl</folder> </files> <config> <fields name="params"> <fieldset name="contact_form" label="Contact Form"> <field name="myemail" type="email" label="JGLOBAL_EMAIL" description="E-mail where you will receive all messages" size="30" class="inputbox" validate="email" /> </fieldset> </fields> </config> </extension>

  3. Here is Main PHP file of module(mod_my_contact_form.php)

    <?php // No direct access. defined('_JEXEC') or die(); echo "I am from Main File"; //Load default.php require JModuleHelper::getLayoutPath('mod_my_contact_form'); ?>

  4. Here is My default.php

    <?php echo "<br>I am from Default file"; //Here I have loaded contact.php to send call there. require_once 'modules/mod_my_contact_form/tmpl/includes/contact.php'; ?>

  5. I didn't do any different thing in contact.php, Just put down your code snippet.

    <?php echo "<br>I am from contact php"; $app = JFactory::getApplication('site'); $app->initialise(); jimport( 'joomla.application.module.helper' ); $module = JModuleHelper::getModule('mod_my_contact_form'); $registry = new JRegistry(); $params = $registry->loadString($module->params); $contact_email = $params->get('myemail'); echo "<br>Here is my params Email=> ".$contact_email; ?>

NOTE : I have just written code which need to go call into contact.php as we wanted to get params into contact.php file. Hence those required and all other stuff is used. So please use your code accordingly in respective files.

  • I'm afraid it doesn't work. The fields tag has been there already in the past. Thanks for the help anyway @Sudhir. – Frostbourn May 22 '18 at 13:51
  • Is Solution not working ? – Sudhir Sapkal May 23 '18 at 3:46
  • I'm afraid it's not. – Frostbourn May 24 '18 at 8:24
  • Ok, Let me check once again, I will be doing same module as you have. Let me try :) – Sudhir Sapkal May 24 '18 at 8:47
  • @Frostbourn - Updated Answer with detailed code, This is working correctly at my end and shows email in contact.php file. Let me know if still you face any specific issue. – Sudhir Sapkal May 24 '18 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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