Im just wondering if javascript and php would both be used on a intermediate form?
Is it practical or can it all be done with php (mostly field validation)?
whats good industry practice?
Also this piece of code wont work any suggestions
if ($_POST[“gname”] ==“” || ==“Enter your given name”){
echo “you need to enter your given name”;
echo “<a href=‘custreg.html’>Return to details form</a>”;
}
Do you want to reject invalid entered names like ^&*()(!@ ?
So what’s the point of using POST if users can enter invalid names as currently allowed by your code.
ok, then this is obviously some sort of homework or learning exercise because in the “real world” you would never accept something like ^&*()#$! as a valid name.
Yeah, but this is the same can of worms that any forum thread is vulnerable to. The advise that practical to impart here will never be enough. After we validate the characters then we get onto the DB insertion (mysqli/PDO/etc.). Then there is the application architecture, and coding conventions and it never ends.
Simplistic solutions also run the risk of false negatives. Some names have accented characters. I’m not sure how to advise dealing with those in a short-ish post.
And what if someone enters Abcdef? Do we need to code pattern recognition, or consult a DB of all known names? How?
if($_POST[‘gname’] == “” AND == “Enter your given name”){
echo “you need to enter your given name”;
echo “<a href=‘custreg.html’>Return to details form</a>”;
}
Server side (PHP) validation is essential and JavaScript is good to have. The fast responses of client side validation improve the usability of the form a lot.
$gname = trim($_POST['gname']);
if( $gname == '' || $gname == 'Enter your given name' ) {
echo "you need to enter your given name";
echo "<a href='custreg.html'>Return to details form</a>";
}
Linking users back to the form will be pretty annoying, as they will lose all their input and have to type again.
You can have the form and validation on the same page, and repopulate the form using [fphp]htmlentities[/fphp] and the POST values to overcome this problem.
If the user inputs are going into a database and data security and integrity are an issue (which they almost always are) then server side validation is a must do.
Client side validation (javascript) is an optional extra because it can be easily bypassed by simply switching off javascript in the browser or the user could send bogus data directly to your form processing script without going to the page containing the input <form>.