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'] ?>"
Related
I have an initial form that submits data to another form, and then that form submits data to itself. The problem is that once that form submits data to itself, all the data submitted from the original form is lost. Is there a way to make sure the initial data is kept after the second form is updated? I know this is possible using SESSION, but is there another way of doing this? I have read a few people saying that it can be done utilizing hidden fields, but I have no idea how to do this. All I need is a simple example to see how its done.
Let's suppose you have this tag inside a form:
<input type="text" name="foo">
You enter some value there and you will be able to reach it on server-side with $_POST["foo"]. Now, let's suppose you have another form of the response of the target page. You can include this value like this:
<input type="hidden" name="foo" value="<?php echo isset($_POST["foo"]) ? $_POST["foo"] : ""; ?>"
Here you check whether the given value was posted and if so, the posted value will be the value of the input. If not, the input's value will be empty string. When you post the form containing this hidden input, the value will be posted as well.
As you have already mentioned, another way of doing this is to store the value in $_SESSION and reuse it. Also, you may store the value in a database and load it.
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
On this form, I have some input field and select boxes that should not be edited by some users.
However, I need those unable fields to be inserted anyway.
I'm thinking about passing those values to a hidden field (should this be done in js ?);
And submit the form by using those hidden fields instead.
Is this a good approach ? Please advice.
You can use hidden fields to pass the data in to your form, but bear in mind that if someone's planning mischief, they can edit the values with tools like Firebug and submit them anyway, so relying on hidden fields may lead to issues.
If you want to be properly secure, you'll have to do everything on the server side - check to see if the client has permission to access those fields when they submit the form. If they do, take the values they've submitted; otherwise, use default values stored in your PHP code instead.
Just put them in hidden field:
echo $form->hiddenField($model,'property');
Just use hidden feilds within your form, like so:
<input type="hidden" name="id" value="00001" />
No js is required.
I would go with disabled on checkboxes and maybe readonly on text fields. The thing is that you KNOW what value they should have when they are submited. So on server side you can just ignore them and use the value you have choosen. And ignore the data if someone is manipulating the post request.
This seems like a simple thing, and maybe I'm just not thinking straight today, but right now I don't see it: How do I post data from a form (in a PHP application) that is not an input field?
The reason I need this is I have a form where the user adds some information in input fields, and this should then update other values in the form based on what the user has entered (doing calculations on this input). This data should then on submit be posted, along with the input from the user.
I tried using form labels, but could not get it to work. For one I couldn't get the value of the form in the jQuery using either .val() or .text(). And I'm not sure if I could get the values of the label in the CodeIgniter function anyway. I also tried simple <p> tags with ids, but that didn't work. I guess it has to be an element with the name attribute...
I'm using a helper in CodeIgniter to get the form values, like so:
$this->input->post('user')
This works fine for input fields, but as explained I need it for non-input elements. Of course I could have input fields that I update in jQuery, but there's a risk that the users will think they should fill them in...
So how do you do it?
How about using <input name="user" type="hidden"> and use Jquery to store the value in there.
Why are you storing input information in non-user-interface elements? Anything you want to be POSTed should be in an input field. Labels are not input elements, they are, well, labels. They label things. What exactly are you doing that you think you can't use input fields? You can disable them, set them to read-only mode, and modify their values in a similar way that you'd modify the text in any other element.
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.