Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 form submit in the same data

I want to create 2 form submit, first button for save data, and the second button for backup. If i click 'Save Data' button, it's work, but if i click 'Save Data as Backup' it's not work.

How to save data as backup with this my code ?

<?=form_open('action/saveData')?>
<?=form_open('action/saveDataasBackup')?>
<label>Your Name</label>
<input type="text" name="name" placeholder="Your Name">
<input type="submit" value="Save Data">
<?=form_close();?>
<input type="submit" value="Save Data as Backup">
<?=form_close();?>

Thanks anyway

like image 433
Ahmad Fauzi Avatar asked Mar 21 '26 05:03

Ahmad Fauzi


1 Answers

Forms can't be nested HTML5 working draft

I would suggest you to use a single form in this case. When you receive form at back end, you can check weather to save the data or to back it up. You can achieve such functionality by adding the name attribute. Your form be like this:

<?=form_open('action/saveData')?>
<label>Your Name</label>
<input type="text" name="name" placeholder="Your Name">
<input type="submit" name="save" value="Save Data">
<input type="submit" name="backup" value="Save Data as Backup">
<?=form_close();?>

In controller method you can check like this:

if(isset($_POST['save'])){
    //perform save operation
}
if(isset($_POST['backup'])){
    //perform backup operation
}
like image 67
Scorpion Avatar answered Mar 23 '26 17:03

Scorpion