Jump to content

Post from addon tpl to module


dotnetrix

Recommended Posts

Hi,

 

The developer docs state that it is possible to post from an Addon Module's tpl file to the module:

 

For forms, use the POST form method to receive user input.

 

Within the output function, the $_GET or $_POST variables can be checked. This can be used to display other output or perform various tasks, once links have been followed.

 

My understanding of this is that, if I have:

 

myaddonmod.tpl

 

<form method="post" action="addonmodules.php?module=myaddonmod">
  <input type="text" name="domain"><br>
  <input type="submit" name="submit" value="Submit Form"><br>
</form>

 

I am submitting to the module and should be able to capture it there:

 

myaddonmod.php

 

function myaddonmod_output($vars) {

$modulelink = $vars['modulelink'];

       $domname = $_POST['domain'];

   *** do things to $domname ***

}

 

But this does not seem to work, running v7.1

 

Any help appreciated.

Link to comment
Share on other sites

So, the admin area itself cannot be templated. There's no documentation of this being supported at all. If that's what you're doing, you can't (at least as far as docs go).

 

That said, it looks like you've got some confusion going on in your template.. Here's an updated version that will do what you want it to do.

The addonmodule.tpl file

{if $domain}
{$domain}
{else}
<form method="post" action="index.php">
  <input type="text" name="domain"><br>
  <input type="hidden" name="m" value="addonmodule"><br>
  <input type="submit" name="submit" value="Submit Form"><br>
</form>
{/if}

Note that the {$domain} is checked, and that the options are a bit more clean

 

Now, for the addon module code itself, an example addonmodule.php here:

<?php
function addonmodule_config() {
$configarray = array(
"name" => "Addom Module Information",
"description" => "Addon Module Dummy",
"version" => "0.1.5",
"author" => "Tom Whiting<br /><a href=https://www.whmcs.guru>WHMCS Guru</a>",
"language" => "english",
"fields" => array(

));
return $configarray;
}
function addonmodule_clientarea($vars)
{

if (!empty($_POST))
{
	$domain = $_POST['domain'];
	return array(
	'pagetitle' => 'Addon Module',
	'breadcrumb' => array('index.php?m=addonmodule'=>'Demo Addon'),
	'templatefile' => 'addonmodule',
	'requirelogin' => true, # accepts true/false
	'forcessl' => false, # accepts true/false
	'vars' => array(
	'domain' => $domain,

	),
	);
}
if (empty($_POST))
{
	return array(
	'pagetitle' => 'Addon Module',
	'breadcrumb' => array('index.php?m=addonmodule'=>'Demo Addon'),
	'templatefile' => 'addonmodule',
	'requirelogin' => true, # accepts true/false
	'forcessl' => false, # accepts true/false
	'vars' => array(
	'testvar' => 'demo',
	'anothervar' => 'value',
	'sample' => 'test',
	),
	);
}
}
function addonmodule_output($vars) {
if (!empty($_POST))
{
print_r($_POST);
}
if (empty($_POST))
{
print("<form method=\"post\" action=\"addonmodules.php\">
  <input type=\"text\" name=\"domain\"><br>
  <input type=\"hidden\" name=\"module\" value=\"addonmodule\"><br>
  <input type=\"submit\" name=\"submit\" value=\"Submit Form\"><br>
</form>");
}

}
?>

 

the difference:

addonmodules.php is an admin area function, not a client side function

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated