动态表单操作 - 使用变量确定操作

发布于 2024-09-12 10:54:06 字数 260 浏览 3 评论 0原文

我在 CodeIgniter 中有一个表单,我需要根据实际表单中的内容更改表单的操作。

即: if

有一个简单的方法可以做到这一点吗?

现在我尝试的解决方法是使用 Javascript 从输入中获取数据,然后将其发送到动态生成的链接 - 但这对于我的情况并不理想。

想法?

I have a form in CodeIgniter, and I need to change the Action of the form based on what is in the actual form.

ie: if <select name="type"> == business then I need action="business/submit"

Is there a simple way to do this?

Right now my attempted workaround is to use Javascript to grab the data from the inputs, then send it to a dynamically generated link - however it's not ideal for my situation.

Thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

物价感观 2024-09-19 10:54:06

我从未使用过 CodeIgniter,但我可以告诉您如何在 PHP 中做到这一点。

你必须明白,如果没有 Javascript,你就无法“动态”地做到这一点。正如您建议您不想使用 Javascript,我建议采用一种肮脏的方式来处理这种情况。

您无法单独使用 PHP 修改操作属性,因此我们必须将其发布到一个 PHP 文件,然后根据您的选择(从您的选择框中),您可以包含您需要的文件。您可以根据您的喜好使用 switch case 或 if 。

这只是指示性的。请不要因为我不遵守标准或没有采取任何安全措施而责骂我!

<?php 
     // sample code snippet 

      if($_POST['type']=== 'something') { 
          include 'something.php'; 
      } 
      else if($_POST['type']=== 'somethingElse') { 
           include 'somethingElse.php'; 
      } 
      else { 
           include 'totallyDifferentOne.php'; 
      }

     // continue your code 

?>

I have never worked on CodeIgniter but I can tell you how you can do it in PHP.

You have to understand that you cannot do this "dynamically" without Javascript. As you suggested that you do not wish to use Javascript, I am suggesting a dirty way to handle this situation.

You cannot modify the action attribute with PHP alone, so we will have to post it to one PHP file and then based on the selection (from your select box) you can include the file that you need. You can use switch case or if based on your preference.

This is just indicative. Please do not flame me for not following standards or not taking any security measures !

<?php 
     // sample code snippet 

      if($_POST['type']=== 'something') { 
          include 'something.php'; 
      } 
      else if($_POST['type']=== 'somethingElse') { 
           include 'somethingElse.php'; 
      } 
      else { 
           include 'totallyDifferentOne.php'; 
      }

     // continue your code 

?>
灵芸 2024-09-19 10:54:06

我不熟悉 CodeIgnitor,但是您不能将表单发送到单个 Action,该 Action 会读取 type 并将请求转发到您希望它转到的任何 Action 吗?

I'm not familiar with CodeIgnitor, but can't you send the form to a single Action that would read the type and forward the request to whichever Action you want it to go to?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文