HTML TwoButtons,保存并移动到下一页,第二个保存并清除表单以添加新数据


HTML TwoButtons that saves and move to the next page and the second saves and clear the form in order to add new data

我想在我的页面中有两个按钮,一个保存数据并移动到网站的下一页,另一个按钮保存数据,然后清除所有字段以输入新数据。我做了一个保存数据并移动到下一页的按钮,但第二个按钮不会清除字段,但也移动到下一页。我该如何解决这个问题?

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

并为您的提交按钮指定相同的名称:

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

或者你也可以试试这个:

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="submit_next" />
<input type="submit" value="Add New & Save" name="submit_new"/>

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

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

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