开发者

Joomla module submit form can't access database

I've been searching the net for an answer to my question but I just can't seem to find one, even though it's probably pretty simple.

I have a joomla module that signs up users to a newsletter, when clicking the submit butt开发者_StackOverflow中文版on I navigate to submitsignup.php file. I do this using the form action value like so:

form action="modules/mod_cmsnewslettersignup/otherfiles/submitsignup.php" method="post" id="subForm"  

Within this submitsignup.php file I can not access any joomla classes, such as:

$db = JFactory::getDBO();  

I know that I can't access any joomla classes because I made direct access to the submitsignup.php file, but I was wondering how do I access this file so that I can have access to all the Joomla classes?

Thanks.


If you are reloading the page when you submit the form, then there is a simple solution that solves both the problem of using a direct URL and of having to load the Joomla framework in that file. Basically change your module code to something like this -

if ($_POST["formsubmitted"]){
    the code you run when the form is submitted
    echo success or failure message
} else {
 the code you run to display the form
    <form action="<?php echo JURI::current(); ?>" method="post">
    <input type="hidden" value="true" name="formsubmitted">
}

Basically, you submit the form to the page that displays it. Then in your module you add a hook to either process the submitted form or display the form depending on what you find in $_POST. You can add some simple security to make sure that the form is being submitted from your site.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜