Rizvan
Rizvan

Reputation: 717

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.

My submit should be redirecting me to do storing database and display those contents with php file?

Can any one having idea what i'm doing mistake or alternative task to do for it ?

Upvotes: 1

Views: 1014

Answers (2)

nivanka
nivanka

Reputation: 1372

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,

the third step will be to redirect to the view.php

which you can do by,

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

note that the variable names you can change as you need :)

Upvotes: 1

Nonym
Nonym

Reputation: 6299

If you really want to separate the pages for form, database_actions and display:

In your php file containing the form:

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

In 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. 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:

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

Upvotes: 1

Related Questions