i have 10 php form in same page, all form field are same but input value will be different, i was wondering is it possible to submit form with single isset code
there services 10 package and all information needed related to package like pricing, quantity, information, services time have been listed with full information, so anyone who need this package he have to simple fill form containing Name, Phone, address and so on fields. as all information have been listed in description form field are same, form package is separated by hidden field which contains package name
if you have same field for all form the you can use single form on modal and get package title with javascript.
but if field are some what different then you can use: if (isset($_POST['submit-p2'] || $_POST['submit-p1'] || $_POST['submit-p3'])
with if else condition but submit button name should be different
all field are same but you have different hidden field for packages that determines the package types: if (isset($_POST['submit-p2'], $_POST['submit-p1'], $_POST['submit-p3']
I don’t think thats the best approach to it, having 10 forms that has same input fields makes no sense at. you can either have one form and then add a drop down field that prompts the user to select which of the package.
Then you now use if X is y do this.
Full code
if($_SERVER["REQUEST_METHOD"] === "POST"){
if(isset($_POST["submitpackage"])){
if($_POST["packagename"] === 'package1'){
// do something with data from other fields and treat as form one
}elseif($_POST["packagename"] === 'package2'){
/ do something with data from other fields and treat as form two
}
}
}
Alternatively if in the case of catalogue display that must have 10 items with forms under them, then you can simply add a hidden field and give it a name with different values.
<input type="hidden" name="identify" value="package1">
<input type="hidden" name="identify" value="package2">
<input type="hidden" name="identify" value="package3">
if($_SERVER["REQUEST_METHOD"] === "POST"){
if($_POST["identify"] === 'package1'){
//treat as form for package 1
} elseif($_POST["identify"] === 'package2'){
// treat as form for package 2
}
}
the second approach is best if you want to have an enquiry form or request info or booking form below every products or 10 products displayed in one page, and you don’t want to write individual code to process all the 10 forms, you can write one processing code but then use then identify value to know where to submit or what to do next based on the value it has