【问题标题】:In joomla 2.5 how can I add a custom php response script to an html form?在 joomla 2.5 中,如何将自定义 php 响应脚本添加到 html 表单?
【发布时间】:2016-10-08 16:15:53
【问题描述】:

我创建了一个自定义 html 表单模块,因为我不喜欢将 joomla 扩展用于表单等。原因是安装新的表单扩展需要我全面了解扩展,我觉得这很烦人。

这是我的自定义 html 表单代码:

<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>

谁能帮帮我?另外,我应该将我的响应 PHP 脚本放在 joomla 目录中的哪个文件夹中。在我的情况下,我特别指的是“HereYouGo.php”

非常感谢您的帮助

【问题讨论】:

  • 这不是您问题的答案。但我只是想我应该让你知道&lt;center&gt; 标签已经是deprecated。有一段时间了
  • 感谢您的更新...它仍然有效

标签: php html forms joomla joomla2.5


【解决方案1】:

为什么不创建一个自定义 html 类型的模块并在那里添加代码。 然后在需要的地方发布模块。

【讨论】:

  • 我的意思是我已经创建了你提到的“自定义 html 类型的模块”。我要问的是我在哪里放置将响应 html 表单的 php 代码。我也在 joomla 中使用 sourcerer 插件...我可以将响应 php 代码放在那里吗?
  • 不要去工具->源代码。直接在出现的文本框中添加 {source} 所有以 {/source} 开头的 php 代码。这应该对你有用。
  • 谢谢...也在考虑这个选项..会按照你说的尝试..再次感谢
【解决方案2】:

首先我想建议最好创建自己的模块或组件,然后使用 mod_html。 mod_html 不适用于表单提交。无论如何,如果您仍然想继续,那么您可以在 Joomla 中创建一个文件夹,例如。 “自定义”并将 php 文件 HereYouGo.php 放在文件夹中。在您的表单中,将 HereYouGo.php 替换为 custom/HereYouGo.php。假设您已经安装了 sourcer 插件。所以你的表单看起来像

{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' ) 是为了避免 CSRF Attack (Cross Site Request Forgery)

现在在您的 php 中检查表单令牌,然后继续您想做的事情。保存在数据库等中或重定向到另一个页面。典型的 php 脚本应该有这些代码才能正常工作,因为它是一个外部脚本

    //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 先生,我非常感谢你。你真的花时间解释这一切。顺便说一下,我个人也位于印度。谢谢一百万
  • @KennyKamei 不客气。如果您的问题得到解决,您也可以将其标记为已解决。
  • 好吧,我确实创建了自己的“自定义 html”类别模块......然后我通过 sourcerer 将我的 html 表单代码插入到模块中......如果你这样做,我没有使用 mod_html 扩展意思是......无论如何,我不能感谢你,阿米特先生......你真的花时间解释这一切......顺便说一句,就个人而言,我位于印度......再次感谢一百万
猜你喜欢
  • 2014-12-14
  • 2012-12-03
  • 2013-12-28
  • 1970-01-01
  • 2013-04-23
  • 2012-04-24
  • 1970-01-01
  • 2013-05-29
  • 1970-01-01
相关资源
最近更新 更多