简体   繁体   English

HTML形成多个号召性用语

[英]HTML forms multiple calls to action

I want to make a call to some php file before that I'm trying to use forms to store user data into database through a php file, but the problem is form can't call two actions in a single form. 我之前想要调用一些php文件我正在尝试使用表单通过php文件将用户数据存储到数据库中,但问题是表单无法在单个表单中调用两个操作。

My submit should be redirecting me to do storing database and display those contents with php file? 我的提交应该重定向我做存储数据库并用php文件显示那些内容?

Can any one having idea what i'm doing mistake or alternative task to do for it ? 任何人都可以知道我在做什么错误或替代任务吗?

If you really want to separate the pages for form , database_actions and display : 如果你真的想要分离formdatabase_actionsdisplay

In your php file containing the form: 在包含表单的php文件中:

<form action="database_actions.php"><!-- means form posts to action.php //-->

In database_actions.php : database_actions.php

# Place code to insert into database and make sure 
# no echo or print_f/r commands are issued
# and no spaces or line breaks at the top before `<?php`
# Then place this at the end of
header("Location: http://host/display.php");

In display.php , you can show whatever output. display.php ,您可以显示任何输出。 If you have values to pass, then you may force the movement through sessions. 如果你有值传递,那么你可以通过会话强制移动。

This kind of approach used to be fine in the old days, MAYBE, but now there are many ways to properly perform the actions you have in mind.. One of them is the Model-View-Controller design pattern. 过去,这种方法过去很好,但是现在有很多方法可以正确执行你想到的操作。其中之一就是模型 - 视图 - 控制器设计模式。

Of course, you'd be better off using an MVC design pattern.. Here's a sample link: 当然,你最好使用MVC设计模式..这是一个示例链接:

http://www.tonymarston.net/php-mysql/model-view-controller.html http://www.tonymarston.net/php-mysql/model-view-controller.html

You can perform a search in google too.. Surely you'll find loads more on MVC patterns.. 你也可以在google上进行搜索。当然你会在MVC模式上找到更多的负载..

my two cents are, 我的两分钱是,

you can have a form like the following 你可以有一个像下面这样的表格

<form action="save_actions.php"></form>

this will post the form to the save_actions.php where the data gets saved, then after saving you can grab the primary key of the data record, using mysqli, or whatever you are using, 这会将表单发布到保存数据的save_actions.php,然后在保存之后你可以使用mysqli或者你正在使用的任何东西获取数据记录的主键,

the third step will be to redirect to the view.php 第三步是重定向到view.php

which you can do by, 你能做什么,

header("Location: /view.php?id=$id");

note that the variable names you can change as you need :) 请注意您可以根据需要更改变量名称:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM