Skip to content
Advertisement

How to get form input fields if name is not known

I have a form which is made dynamically with jquery ajax and input fields names values comes dynamically, I want to update these fields with php I am not sure how to do this.

when form is submitted I does not know what will be the name of input fields.

<form id="modalform" action="#" method="post">
 <input type="text" name="46" class="form-control margin-top20 " value="selcetopt 1" />
 <input type="text" name="50" class="form-control margin-top20 " value="selcetopt 2" />
 <input type="text" name="56" class="form-control margin-top20 " value="selcetopt 3" />
 <input type="text" name="66" class="form-control margin-top20 " value="selcetopt 4" />
 <input type="text" name="96" class="form-control margin-top20 " value="selcetopt 5" />
<input type="submit" value="Update" name="submit" />
 </form>

Advertisement

Answer

You can iterate over $_POST to get all input filed values, Based on your question I have added a sample code below

<?php
if(!empty($_POST)){
    foreach($_POST as $key => $value){
        // Preprocess $key which holds name of input field
        // You can apply your logic to process value for an input $key here 
        // From your example it looks like name is a number so special case can check within a condition for $key as number

        if(ctype_digit($key)){
            // This will only get the value of all dynamic input fields if name is a number     
        }
    }
}

I hope it helps you

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement