Submitting multiple form with single isset....?

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

if (isset(($_POST['submit-p1'])) || (($_POST['submit-p2']))) {
        $fm_name = $_POST['fullname'];
        $fm_package = $_POST['package'];
        $fm_email = $_POST['email'];
        $fm_address = $_POST['address'];
        $fm_phone = $_POST['phone'];
        $fm_message = $_POST['message'];

can we do it, is there any other ways… i dont want to copy paste same code for all 10 form just changing submit button name…

Could you please provide a high level overview of what you have going on and why you have 10 forms with the same fields on one page.

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

finally solved multiple form submission having same fields with single isset code, working well and fine… :yum: :smiley:

Perhaps you could post your solution, in case it helps anyone in the future who has the same problem.

1 Like

if you have same field for all form the you can use single form on modal and get package title with javascript.

  1. 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

  2. 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']

If you’re only checking to see whether the page was submitted, then you should really be using

if ($_SERVER['REQUEST_METHOD'] == "POST") { 

and then check which button was pressed within that.

2 Likes

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

<select name="packagename">
<option>package1</option>
<option>package2</option>
<option>package3</option>
<option>package4</option>
</select>
<input type="submit" name="submitpackage" value="submit">

Then on your php you do something like

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
}
}
}

@synerdb,

I would like to see your complete form code. Something doesn’t smell right.

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

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.