How to submit multiple PHP forms while each form has its own submit button?
To generate your forms, use a variable to increment:
<?php
$i = 0;
while ($rowTechmen = $techmenQuery->fetch(PDO::FETCH_ASSOC)) {
?>
<form method="post">
<input type="text" name="textbox"/>
<button type="submit" name="submit_<?php echo $i ?>">Submit</button>
</form>
<?php
$i += 1;
}
?>
Then if you need to identify which form was submitted, you can do:
// When a form is submitted
if (isset($_POST) && !empty($_POST)) {
// Get the submit number
$submit_name = preg_grep("/submit_/", array_keys($_POST));
$submit_id = ($parts = explode('_', $submit_name[1]))[1];
// Display the data for testing
var_dump($submit_id);
echo $_POST['textbox'];
}
Of course you can replace $i
with an ID from your database. Documentation of the used functions:
preg_grep()
array_keys()
explode()
Submitting multiple forms with one submit button that also passes post data
Solved it myself. Rather than having a form on every tab, I simply wrapped every tab item inside of an all-encompassing form. Works great.
Thank you to all that answered.
submit multiple forms with single submit button in javascript
The problem is that appendChild()
takes the element away from the form, modifying the elements
array as well as its length. To avoid this, you can e.g. store the number of elements in a variable and process the array of elements starting from the last element:
var frm = frmCollectFrom.elements;
var nElems = frm.length;
for(var ix = nElems - 1; ix >= 0 ; ix--)
frmCollector.appendChild(frm[ix]);
Submit multiple forms by single button
I solved it. The problem occurred because the every form has the same id. By an incremental variable I made changes in the form id to vary from one to one. Then problem solved. thank you very much everyone who tried to help me..!
How to place two forms on the same page?
You could make two forms with 2 different actions
<form action="login.php" method="post">
<input type="text" name="user">
<input type="password" name="password">
<input type="submit" value="Login">
</form>
<br />
<form action="register.php" method="post">
<input type="text" name="user">
<input type="password" name="password">
<input type="submit" value="Register">
</form>
Or do this
<form action="doStuff.php" method="post">
<input type="text" name="user">
<input type="password" name="password">
<input type="hidden" name="action" value="login">
<input type="submit" value="Login">
</form>
<br />
<form action="doStuff.php" method="post">
<input type="text" name="user">
<input type="password" name="password">
<input type="hidden" name="action" value="register">
<input type="submit" value="Register">
</form>
Then you PHP file would work as a switch($_POST['action']) ... furthermore, they can't click on both links at the same time or make a simultaneous request, each submit is a separate request.
Your PHP would then go on with the switch logic or have different php files doing a login procedure then a registration procedure
Related Topics
Extension Mysqli Is Missing, Phpmyadmin Doesn't Work
Executing Python Script in PHP and Exchanging Data Between the Two
How to Pass Variable Between Two Web Pages With PHP Without Using Session
Laravel Composer Sees Wrong PHP Version
Finding the Longest Gap Between Multiple Intervals
Laravel 6: Call to Undefined Method App\\User::Createtoken()
Remove Comma on Last Item of Foreach
Auto Update Cart on Quantity Change in Woocommerce Cart Page
How to Prevent Multiple Inserts When Submitting a Form in PHP
PHP - Failed to Open Stream: No Such File or Directory
Getting a File to Download Instead of Opening the Browser
Php Warning: Mysqli_Connect(): (Hy000/2002): Connection Refused
Codeigniter - Show Information in Modal Window
How to Set Current Date as Default Value of an Input
How to Fix Warning Illegal String Offset in PHP
Easiest Way to Replace All Characters in Even Positions in a String.