Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.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 HTML两个按钮,用于保存并移动到下一页,第二个按钮用于保存并清除表单以添加新数据_Php_Html_Forms - Fatal编程技术网

Php HTML两个按钮,用于保存并移动到下一页,第二个按钮用于保存并清除表单以添加新数据

Php HTML两个按钮,用于保存并移动到下一页,第二个按钮用于保存并清除表单以添加新数据,php,html,forms,Php,Html,Forms,我想在我的页面中有两个按钮,一个保存数据并移动到站点的下一页,另一个按钮保存数据,然后清除所有字段以输入新数据。我做了一个按钮,保存数据并移动到下一页,但第二个按钮没有清除字段,但也移动到下一页。我怎样才能解决这个问题 if(isset($_POST['submitted'])) { . . . header('Location: education.php'); } 我的按钮代码是 <input type="submit" value="Next" na

我想在我的页面中有两个按钮,一个保存数据并移动到站点的下一页,另一个按钮保存数据,然后清除所有字段以输入新数据。我做了一个按钮,保存数据并移动到下一页,但第二个按钮没有清除字段,但也移动到下一页。我怎样才能解决这个问题

if(isset($_POST['submitted']))
{
    .
    .
    .
    header('Location: education.php');
}
我的按钮代码是

<input type="submit" value="Next" name="submit" />

<input type="submit" value="Add New & Save" />

尝试以下代码:

if(isset($_POST['submitted']))
{
    if($_POST['submitted']=="Next")
    {
        //perform inserting data and redirect
        header('Location: education.php');
    }
    else if($_POST['submitted']=="Add New & Save")
    {

        //Clear all fields of form and save the data.
    }

}
if(isset($_POST['submit_next']))
{
    //perform inserting data and redirect
    header('Location: education.php');   
}
else if(isset($_POST['submit_new']))
{
    //Clear all fields of form and save the data.      
}
并为“提交”按钮指定相同的名称:

<input type="submit" value="Next" name="submitted" />

<input type="submit" value="Add New & Save" name="submitted"/>
并为“提交”按钮指定不同的名称:

<input type="submit" value="Next" name="submit_next" />

<input type="submit" value="Add New & Save" name="submit_new"/>

实现所需功能的一种方法是将“添加新”按钮作为单独的表单。一个页面上可以有多个表单。因此,请从此表单中删除“添加新内容并保存”按钮,并对一个表单使用“下一步”按钮,对第二个表单使用“添加新内容”按钮

显然,您必须将标题url更改为当前页面url(即标题('Location:education.php')必须更改为指向表单所在的页面。这将保存数据并通过再次调用刷新页面

而且,您必须包含一个条件语句,该语句将确定单击了哪个按钮,以确定要导航到哪个页面