You can use one form with a hidden field for id . If this field is set, then you must update the $_POST['id'] entry to the rest of the forms. If the field is not set (that is, it has value = ""), you must insert the form data in a new record.
You will set the id field according to the action, for example, /data/edit/1 set the id field to value , and / data / new`, will not set the value for it.
For example, your submission may be
<form action="/data/edit/1"> <input type="hidden" value="<?php echo $data->id; ?>" /> <input type="text" value="<?php echo $data->name; ?>" /> </form>
For a new entry, call up your view with the following data
$data->id = ''; $data->name = '';
In the case of a known record, just run the $data object with the data
$data->id = $record_id; $data->name = $record_name;
Elazar leibovich
source share