Connecting forms in php - php

I have a form which has details like name,number,email,etc... I have 3 forms like this.
So I have created a file called form.php which has the form and I am including it in my page.
Each of the form has some details that is not in the other forms like:
One form has Number of slots while the other 2 don't have it.
I explicitly added the uncommon part of the form in each page differently as a form.
Now I have 2 submit buttons. So how do I avoid two buttons and connect the 2 forms as the data from the complete form? It has to added to a single table.

Use $_SESSION in the first 2 forms to get the data to the third form.
http://php.net/manual/en/reserved.variables.session.php
Then retrieve data from the session in the third form and place it as a hidden field.
Then the submit button on the last form will submit all the data i.e from the fields in the third form as well as the data carried from the first two forms.

Related

How to retain all form values when using form chaining in a web application?

I have an html form page that I submit, and resulting page opens to another form that requests supplementary information, in addition to form 1. When I submit the 2nd form, values from the first form are not submitted along with it, so I only get values from form 2.
By default I get this:
form1 -> [submit] -> form2 -> [submit] -> [result page with form2 values only]
How can I receive values from both forms?
In my case 2nd form is dependent on the first, as in it needs to know values from the first form to exist and the forms are not independent.
You can store the data from the first form in session/local storage and post this along with Form2 data. Once, submit is successful, clear the storage.

Two forms submitting data to a single page - can the PDO be processed on the submitting page?

I have a sign-up section to my webpage, which is split into 4 forms on 4 different pages. Each form also has an 'edit' equivalent so users that are already signed up can edit their profile:
The data entered by each user is added to the database using PDO statements.
By using POST, the data on 'signup_form1.php' is processed and submitted in the header of signup_form2, and so on. The same applies to the edit_form sequence. The fourth and final form for both signup and edit are processed on the buyerhub.php webpage.
My question is the following:
Is this the correct way to go about handling the data (ie the form data is actually processed on the next page rather than the page containing the form). If so then how would the buyerhub.php page determine whether the data has come from the signup form or from the edit form?
It seems to me that following the sequence of data is quite 'messy' if the form data is not processed on the same page as the form, and it also introduces some form of conditional logic if more than one form redirects to a webpage (in this example main_user_hub.php).

How to fill a form with data from Mysql database?

I have two HTML forms in a php file(Control.php). I have four dropdown list as filters in Form1. once i click submit button in Form1, i have to pass the values selected from Form1 to another php file(Actions.php) through POST method, where i pass query with the filters and retrieve data from Mysql database(if record is present in the database for those filters). I was able to make it work so far.
Now i want to fill my Form2, with the data retrieved from database based on the filters. if no data is available, i want to set all the elements in the form blank for adding new data.
How to add a new data and modify(update) existing data in same Form.
You can pass the data retrieved from the first query to the other pages in the PHP session. Then your script can simply copy the contents of the session (or NULL) into the value= attributes of the form.

Working with multiple forms at once in PHP

I need to make an application which dynamically generates some number of forms and processes them. The user should be able to deal with each form individually without resetting the entered values in the other forms.
What I have right now is a master form that uses JS to generate some number of forms. The forms are all the same (i.e. I iterate on include("myForm.php").
My problem is that every time I submit one form, the values in the other forms get reset. How do I fix this?
This is a three-step process:
Ensure that each form element on the page has a unique name and ID.
Store submitted values in the user's session.
Use PHP to insert the previously-entered values into the form fields when a form is posted.
Post the form with AJAX, this doesn't refresh the page so you won't lose the values entered in the other forms

Post Array Data from Multiple Selects to Mysql

I have a form-1 which has 4 fields. when the user inputs data in these and hits submit, he is taken to form 2 for further selection of more items from multiple selection box. after selections are complete, he is prompted to update and on updating, all the data has to go to a third form for processing.
currently i am passing the single fields data from second form to third form by <input type="hidden" name="abc" value="<?php echo $x[0] ?>">
I am getting stuck as to how to retreive all multiple selected items from the array, perform a calculation on them and then post to mysql and then update the user with posted information.
or is there a better way of doing this, pl. guide me. my fields are:-
first page
customer id - single selection field
date - input
segment selection - single selection field
second page
items inputs - itemid, quantity,price (these are in one row and user will dynamically add or delete rows based on requirements. i have done this through Javascript)
now after all this, i want to gather all details of customer, segment, items(id,quantities,prices) and then post them to mysql.
If you want to use separate pages you can use either hidden inputs fields or sessions to pass along their selections. With sessions, you'd just store the array of data in $_SESSION and use session_start() on each page to get the session from the previous page. With hidden inputs, you can store them just like you would with session, and when they click POST you will rewrite them into the form. Are you stuck on specific aspect of doing this?
On the final page use either the session or the hidden fields (depending on your chosen method) + the final POST, to query MySQL.
Note: As Zirak mentioned in the comments, you could also do this using a single page. You'd use one of the same methods described above, except it would post to itself rather than to another page. This might be a faster/better way to code the page... If you opt for the single page method just ensure that you make it possible to go back, both through their browsers back button and a link you provide.

Categories