how to use a hidden field for multiple form submition - php

I have a form that i want to filled up by the end user in few steps.
in the first step i want to let them fill Name,Address,Mobile number.
And when click next button i want to appear another part of the form to fill the other details such as upload a image .
i did research online,i found 2 articles useful,
One thing is about sessions and the other thing is about hidden fields.
In my opinion i think sessions are not a good way to use for form submitting.Because some browsers are might have disabled sessions.
So ill go with hidden fields.
In my database i have a unique id which is auto increment.What i want to do is to let user to submit a form.In the first step i want them to submit their name,addres,mobile number(In this time it is inserting data to the database- Only for couple of columns.) And in my database i have a field for upload a image.In the first step it gets a null value.I want to update that null value in the next step by getting a that id from the first step
Please give me the basic idea to start this.A little help much appreciated!
Thanks in advance

you can try like this:-
You can add a class on the input which you want to hide
<input type="text" name="example" class="inputHidden">
after that add style in your page like this
<style>
.inputHidden{
display:none;
}
</style>

If you're trying to place the form data into new, hidden inputs - take the initial input.
<input type="text" name="example">
On the next page add a hidden input.
<input type="hidden" name="exampleP2" value="<?php echo $_POST['example']; ?>">

You can get form submited data and use it in input hidden fileds
for e.g. in first form you have
name ,email etc fields
in other form you have more fields
here you can use <input type="hidden" name ="firstname">
and thus you can add as many as you want

Related

Codeigniter disable storing previous form data

There is a Codeigniter scenario wherein the First form contains textarea, checkboxes.
After filling in user goes to 2nd page. There is button Previous to go back to 1st page.
The problem is 1st form's is populated with values set before.
I would like to have a page without auto populating.
Any help would be great. Thanks.
Your navigator keep in cache your data, look to :
<input type="text" name="foo" autocomplete="off" />

Saving multiple $_POST from a single text form

I have a page with a single form, and a submit button.
What I'm trying to achieve is when some text is entered it's saved to the $_POST array and outputted below. However, what I then want to do is use the same form to then perform the same task (albeit different text), but ensure both/multiple values are saved.
I'm assuming the best way to achieve this would be to save them to an array as the page is reloaded; but i'm not sure where to start.
Thank you.
What you could do is make some hidden fields and init them with the data from the form,
wich has been edited the first time.
Then when it is posted for the second time you could use the values from the hidden fields and the new information from the normal fields
<input type="hidden" name="hiddenFieldName" value="<?php $_POST['normalFieldName'] ?>"

Autocomplete form and a hidden input

Basically, I have an input field in my form that is set in the CSS to display: none and I was wondering if auto fill programs fill in hidden fields? I set the value of the field to time() on load and compare it to the time the form is submitted to tell if the user is a human or bot.
Here is my code for the hidden field:
<?php
$loadTime = time(); // Initial time that the page loads is checked against the time the form is submitted and if its too fast, its probably a bot
?>
<input type="text" name="loadTime" id="loadTime" value="<?php echo $loadTime ?>" maxlenght="50" />
Instead of a text input with display:none; you should use <input type="hidden" .../>. Like this auto fill programs won't modify its value. Another (and safer) option is storing the time value as a server variable so that it can't be modified
I was wondering if auto fill programs fill in hidden fields?
(EDIT: By hidden I thought that you were asking for this:
<input type="hidden"...
)
Answer is no. Also, I would remove that hidden field because somebody could manipulate that value. I would rather store that time data in session because it's stored on server and not on client's computer.
Even if auto filling fills the form, It won't be visible since it is set in CSS. If you want the text to become visible, change the class CSS while JavaScript changes / fills the input. You can do both filling text and change CSS both, at the same time, using JavaScript.

Form 2 sql gets fields from Form 1

I have two forms form 1 and form 2.
The form 1 has 20 fields of data and it's action is to update.
In form 2 I have another action, but I want to get the 20 fields of data from form 1.
Is there any possible way to do this and how? Also form 1 and form 2 are in the same page.
I have already a solution which is putting 20 hidden fields in form 2 so form two can
get it from there which is tedious. But can I ask you guys is there a much easier idea?
You can save all the input from form 1 in a session variable and restore it in form 2. For that purpose, write a function which stores all $_GET and $_POST variables in an element of the $_SESSION array (using the parameter name as the key).
The "problem" is something that ever PHP developer has at some point solved.
The best way to do this would be to save data from previous form in $_SESSION. But this will be a valid solution, if you are filling out the form, while in the same session.
If you are building something like a e-commerce site, where user has to fill out several payment forms, or some large test-application, where students fill out multiform tests, it might be better to store data from each form in DB and associate it to UserId. This way the user gains ability to continue filling out the form from different location.
P.S. If you are using AJAX instead, you will mostly just add another layer of complexity on top of existing application. Especially if your skills in JavaScript are limited.
I think your solution isn't bad, simple and Swift !
But the only better way, is ajax.
In ajax you are not limited to a form, you can get every fields from every forms and then send them manually.
If you are not familier with ajax, and you want to use your non-ajax solution, you can use one form and put all fields of two last forms in this new single form, and use one action file to response to this form.In server side you can check the value of a field which is unique.
client side :
<form action="test.php">
<!-- fields of form 1 -->
<input type="text" name="text1"/>
<input type="text" name="text2"/>
.
.
.
<input type="text" name="text20"/>
<!-- fields of form 2 -->
<input type="text" name="text21"/>
<input type="text" name="text22"/>
.
.
.
<input type="text" name="text40"/>
<input type="submit" value="send"/>
</form>
server side:
<?php
if ( isset($_GET["text1"]) )
//do related jobs to form 1 here, and you can use all of filled fields
else
//do related jobs to form 2 here, and you can use all of filled fields
?>

Passing information from forms and your own information

How do I pass information from my form plus some additional data when submitted the form. For
example if I am using PHP
I have a form and I set the method to GET; now all the fields in the form will be sent in the URL, now suppose if I want to keep a track of how many times the submit is clicked, for that if I pass the variable count along with all the data through URL, how do I do that?
How do I append this data to the existing form's data?
OR suppose if I have a field in my form where I allow to user to enter name of their employs; initially it will show 4 fields for the data, but if I click the submit type button that says MORE, then it will display 4 more fields, and similarly if again he presses more it shows 12,
so I was thinking maybe I could sent a variable $count along with the form data through URL, but I don't know how to do it.
I would user a hidden field with the "count" value. It will then be passed with all the other form input variables but won't actually be visible to the user on in the form:
<input name="field_name" type="hidden" value="cout_value_that_changes" />
You can change - Field_name - to what ever you want it to be and the value should be incremented every time the submit button is pressed - incremented with PHP -
something like:
$count++;
value="<?php echo $count;?>"
Best solution for your requirement seems Use of JQuery.
Add your fields dynamically using JQuery.
For ref. you may check : http://docs.jquery.com/Main_Page
Without using JQuery, you can have Hidden field which would contain count of the field.
we have to pass count in GET request and while showing field in php, check count field.

Categories