Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果选中单选按钮,则提交到其他页面_Php_Jquery_Forms_Session - Fatal编程技术网

Php 如果选中单选按钮,则提交到其他页面

Php 如果选中单选按钮,则提交到其他页面,php,jquery,forms,session,Php,Jquery,Forms,Session,我有这个: <form method="post" id="kl" action="step2.php"> <input type="radio" name="rubrik" value="bussines"></input> <input type="radio" name"rubrik" value="private"></input> <input type="image" value="submit" src="/im

我有这个:

<form method="post" id="kl" action="step2.php">

<input type="radio" name="rubrik" value="bussines"></input>
<input type="radio" name"rubrik" value="private"></input>

<input type="image" value="submit" src="/images/submit.png" alt="Submit" />

</form>

我基本上想要的是:当选中第二个单选按钮时,将表单提交到step2a.php,一个不同的文件。我该怎么做?Jquery、Javascript、php?

您可以使用Javascript绑定一个提交监听器来检查单选按钮的值,然后设置表单的action属性,但在服务器端执行以下操作会更简单、更可靠:

<form ... action="step-selector.php">


您可以使用JavaScript绑定一个提交监听器来执行此操作,该监听器检查单选按钮的值,然后设置表单的action属性,但在服务器端执行以下操作会更简单、更可靠:

<form ... action="step-selector.php">


有多种方法,具体取决于你想要什么


看看这个,它可能会帮助你到达那里

有多种方法,具体取决于你想要什么


看看这个,它可能会帮助你到达那里

您可以使用form.submit作为onclick处理程序,而不是onchange,并更改操作

<input type="radio" name"rubrik" value="private" onclick="this.parentNode.action='yourOtherFile.php'; this.parentNode.submit()"></input>

您可以使用form.submit作为onclick处理程序,而不是onchange,也可以更改操作

<input type="radio" name"rubrik" value="private" onclick="this.parentNode.action='yourOtherFile.php'; this.parentNode.submit()"></input>

您可以通过将表单修改为:

<form method="post" id="kl" action="step2.php">

<input type="radio" class="radio" rel="step2.php" name="rubrik" value="bussines"></input>
<input type="radio" class="radio" rel="step2a.php" name"rubrik" value="private"></input>

<input type="image" value="submit" src="/images/submit.png" alt="Submit" />

</form>

您可以通过将表单修改为:

<form method="post" id="kl" action="step2.php">

<input type="radio" class="radio" rel="step2.php" name="rubrik" value="bussines"></input>
<input type="radio" class="radio" rel="step2a.php" name"rubrik" value="private"></input>

<input type="image" value="submit" src="/images/submit.png" alt="Submit" />

</form>

当然,您可以通过Javascript实现这一点,但Javascript并不是实现这一点的方法,因为它可以并且将在某些用户的浏览器中被停用。最好的方法是,您只需在step2.php中执行所有检查,然后通过适当的HTTP头将用户重定向到他应该去的页面。当然,您可以通过Javascript来实现这一点,但Javascript不是实现这一点的方法,因为它可以并且将在某些用户的浏览器中停用。最好的方法是,您只需在step2.php中执行所有检查,然后通过适当的HTTP头将用户重定向到他应该去的页面。rel有一个定义的含义,它不是保存JavaScript任意数据的属性,也不会出现在输入元素上。不要这样滥用它。rel有一个定义的含义,它不是用来保存JavaScript任意数据的属性,也不会出现在输入元素上。不要那样滥用它。回答得很好。正是我所需要的,正是我最需要的。谢谢你,昆汀!回答得很好。正是我所需要的,正是我最需要的。谢谢你,昆汀!