How to get the data from input without attribute name? [duplicate] - php

This question already has answers here:
Does form data still transfer if the input tag has no name?
(3 answers)
Closed 9 years ago.
I read $_POST is empty after form submission topic and I wondered how to get the data from input without attribute name?
<input type="text" >
var_dump($_REQUEST)//empty
var_dump(file_get_contents('php://input')) //empty

Basically, the form should be specified its name. If not, you cannot get it from the server-side.
However, the form without name is also valid in HTML5. The reason is that you might sometimes want to use for form submission via AJAX or Javascript app. In many cases

Related

Adding Values to Array and keep existing values [duplicate]

This question already has answers here:
Keep values selected after form submission
(12 answers)
Closed 3 years ago.
I am trying to find what the easiest way to keep form values after post. I am really trying to have to keep from learning ajax right this second for the one form, Plus I am not sure how hard it would be to implement ajax into my already existing google map page. So I am trying to find a way to retain the values of two date fields after submit has been pushed
If you are looking to just repopulate the fields with the values that were posted in them, then just echo the post value back into the field, like so:
<input type="text" name="myField1" value="<?php echo isset($_POST['myField1']) ? $_POST['myField1'] : '' ?>" />
you can save them into a $_SESSION variable and then when the user calls that page again populate all the inputs with their respective session variables.

why does my User registration form have some fields pre filled when it actuall suppose to be blank. [duplicate]

This question already has answers here:
How can I clear form values after successful form submission
(4 answers)
Closed 4 years ago.
I built a simple user registration form using Xtml, php Myadmin.i expect all the field to blank prior to inputing data.But each time i refresh the user registration page some field on the form will be pre filled. . What should i do so that form field should be blank prior to inputing data?
You can use the autocomplete tag like this
<input type="text" name="bar" autocomplete="off" />
To turn this browser behaviour off. Be aware that this does not work completely at some Firefox versions.

How to get the post data without form builder [duplicate]

This question already has answers here:
Access POST values in Symfony2 request object
(9 answers)
Closed 8 years ago.
Normally I am using formbuilder to get the post data from form.
However,now I need very simple form not relevant with entity.
I can get the method like this and
if ($this->getRequest()->isMethod('POST')) {/
I want to get the each form data.(name is form name)
echo($this->getRequest()->get('name')->getData());
it shows error.
I used to use formbuilder and bindRequet normally to pick the data from form object.
How can I get the each form data from this->getRequest() without using formbuilder?
You could get it from the request property:
$this->getRequest()->request->get('foo');

Prevent HTML file field from being delete after PHP validation roundtrip [duplicate]

This question already has answers here:
Can you re-populate file inputs after failed form submission with PHP or JavaScript?
(2 answers)
Closed 10 years ago.
I have a HTML file field <input name="File" id="FileName" type="file"/>. When I submit the form, I do receive the file, all fine. However, when I validate the user's input and cannot accept the values provided, I will need another round trip. As usual, I will redisplay the form plus error messages.
For text field or textarea I can set the (already) provided value, e.g. by value or just echo the value in the textarea. How could I do the same for file fields? I want to avoid that the user always has to reselect the file in the browser.
-- added --
Comments below are right - there are workarounds described in the mentioned SO questions:
PHP remember file field contents
Can you re-populate file inputs after failed form submission with PHP or JavaScript?
Restoring the value of a input type=file after failed validation
This is not possible - you have to store the file on the server to do this. Then you can show the user a short info about the already stored file and the option to upload a new file or delete the file

How to keep form values after post [duplicate]

This question already has answers here:
Keep values selected after form submission
(12 answers)
Closed 3 years ago.
I am trying to find what the easiest way to keep form values after post. I am really trying to have to keep from learning ajax right this second for the one form, Plus I am not sure how hard it would be to implement ajax into my already existing google map page. So I am trying to find a way to retain the values of two date fields after submit has been pushed
If you are looking to just repopulate the fields with the values that were posted in them, then just echo the post value back into the field, like so:
<input type="text" name="myField1" value="<?php echo isset($_POST['myField1']) ? $_POST['myField1'] : '' ?>" />
you can save them into a $_SESSION variable and then when the user calls that page again populate all the inputs with their respective session variables.

Categories