Hi, whenever a user fills out a form and leave certain inputs that
are not required, it still sends that input field in the email. is their
a way not send the empty fields?
this is an example of what I got in the email test I did to myself
I didnt fill in certain fields and they were still sent blank.
I’m not a PHP person (or a programmer), so what I’m going to suggest will work, but it’s very inefficient. Still, we noobs have to survive somehow!
So, for each item you want to make conditional, you could replace something like this—
I should have asked if there’s a separate script to handle the $validation. If so, there might be more to it than this. Without it, your form is pretty insecure.
To get rid of the ~60 lines of code that essentially all do the same thing.
for example, instead of $PatientName = Trim(stripslashes($_POST['PatientName']));
for each $_POST variable, it loops through them all creating a variable from the key and and assigning the “processed” value
Yes - provided that timming off the leading and trailing whitespace and removing slashes is all that is needed to ensure that all the fields contain valid values. If that isn’t the case then your original code doesn’t work either (even if you were to fix the typo)
The exact details of constraint validation aren’t all that clear to me, but AFAICT it’s more for immediate feedback to the user than it is to replace proper validation / sanitization
That is, use it to help honest users, but don’t rely on it alone for protection against malicious users.
Any client side validation should be repeated on the server as a minimum (assuming that there is no validation that can’t be done easily in the browser that you only apply on the server).
Some older browsers don’t even recognise the validation from html. It is useful, but not to be relied upon.
Since you are using php to process the form, it would seem natural to use php for validation. Using server side scripting would also get around problems with people not having js enabled.
True, at the time of writing, only Chrome and Opera supported HTML5 validation,
although other browsers are expected to follow. Most developers at the moment
will continue using Javascript to validate forms…