javascript - How do I validate dynamically created controls in jquery at server side - Php
I am creating an applicaiton where hundreds of controls are created dynamically in Jquery as below.
var $link='<a id="bucket'+data[0].ID+'" class="Initial" href="#"></i></a>';
$($btnGroupdiv).append($link);
While adding controls I am assigning unique ID to each control.
And this is how I am identifying each control while accessing it.
$(".Initial").click(function(){
var $pid=this.id.replace("bucket","");
But here's the issue.
These IDs can be changed at browser with "Inspect Element" option.
ServerSide Situation
IDs which I have assigned to controls, are the primary keys of row in table called employee.
So changing ID at browser can temper data in a different row than intended.
How do I validate these controls at serverside, if ID is changed or not or How do I restore original ID of an element at server side??
I hope my question is clear enough.
Any help is apppreciated.
For everyone who thinks this is not possible.. I would ask - How does facebook or even StckOverflow do it??
Answer
Solution:
You need to define it differently for it to work with dynamic elements:
It is impossible to detect if anybody has changed the ID via the browser.
Answer
Solution:
You can't (software rule n°1: never trust user input).
What you can validate serverside is:
And this is it ! If a user is doing an action he is allowed to, on valid data, why should he be stopped to do so ?