0
votes

I need something very simple. I have different html pages (in total eleven) with forms that when submitted they will send via post the values of an input form. These pages are very different, with inputs tags with different names and functions ecc... The php must save data inside a pre-existed excel file so i pass to my php page also the cell where save the data. But because there are very different pages with different tag names, i want only to write a php file that use the $_POST array using numeric index instead of the name of the tag as key. That's possibile?

An example of part of a form of one of the all pages is this

Client name <input type="text" name="client_name"/> <input type="hidden" value="A8"> 

An esample of a second page could be

Address of you friend <input type="text" name="address"/> <input type="hidden" value="A1"> <br>
<br>

When one of these send via the submit button using method post, the content in $_POST[1] will be A8 if the php page is called from the first html page and will be A1 if the php page is called from the second html page?

1
You are using a MSExcel file as a database? OMG! - symcbean
I'm not sure that it's guaranteed, but the order that you use for the INPUT fields in the HTML will carry through to the order of the key/value pairs in $_POST. I.e., just maintain a counter as you iterate over $_POST. The first key/value pair will correspond to the first INPUT on the form, etc. (You still have to give them names though.) - Alex Howansky
Why not just map out potential fields and then check in your form processor with something like if( isset($_POST['formfield']) ){ // do stuff here. }? Then you could still have one script that can handle multiple forms with different fields? - pj100

1 Answers

0
votes

Form controls without names cannot be successful controls.

Only data from successful controls is sent to the server in the HTTP request.

Since your controls don't have names, they won't be in the data, so the server will never get the data. It can't pass the data to PHP and PHP can't use it to populate to $_POST.


If they had names, but you didn't know what they were, then you could loop over the keys of the $_POST array like any other associative array.

foreach ($_POST as $key => $value) {
    echo htmlspecialchars($key);
}