Quote:
Originally Posted by lld
I have a page that lets the user to add record into the database. After the user clicks on the 'submit' button, I would like to perform a check for duplicate record in my database. (I suppose this is to be done in PHP?).
Then if an existing record is found in database, I will ask the user if he wants to replace the existing record using a confirmation popup. (This uses javascript?)
|
I would approach this functionality with something like this:
1) User fills out all inputs in a form
2) When the user clicks the Submit button, use javascript to validate all the inputs.
3) If they are all valid, send an ajax request to the server to query the database for a duplicate record. The ajax function returns a value of true or false depending on whether thre is a duplicate record.
4) If there is no duplicate record, use javascript to submit the form by returning true to the onsubmit event handler.
5) If a duplicate record exists, display a prompt asking the user to confirm if they want to replace the existing record with their new data inputed in the form.
6) If the user confirms they want to replace the old record with the new record, use javascript to submit the form.
7) If the user chooses to not replace the old record with the new data, then simply return false to the onsubmit event handler which will abort the form submission.
Whether the user submits a new record or chooses to overwrite an existing record, all the <form> data must be validated on the server because the js validation can be easily bypassed and a malicious user could send bogus data to the server side php script without having used your form at all.