The "is there a better way" topics like your tend to get subjective. Your question might be more geared for somewhere like Code Review Code Review. But anyway, here are a few thoughts I saw right off.
- Global variables is kind of asking for trouble. Instead of have your variables get set inside of functions, simply return
true
orfalse
based on the test and let the calling code handle how to present the message to the user.
Example:
if(!checkHours($hours) {
print("Please choose an option from the drop down list");
}
Many of your functions exhibit the same kind of test. I see a lot of
if($var === "pleaseselect")
. Those can be made into a single function and then the fields that need validation in that manner use that one function. Changes in the future become easier when you aren't tracking down a dozen function that are doing the same thing.Some of the tests are redundant. On fields like the phone number, first you check to see if the string is empty, then you compare it to a regular expression if it is not empty. You can omit the empty test since an empty string will be caught during the regular expression test.
There are some other small things I would do differently, but again, none of that is going to affect the correct operation of your code. I can't say how much more "efficient" the code would be with changes. You would have to create a benchmark test to profile your code to tell the difference. But your code would definitely be more readable and easier to maintain.
The "is there a better way" topics like your tend to get subjective. Your question might be more geared for somewhere like Code Review. But anyway, here are a few thoughts I saw right off.
- Global variables is kind of asking for trouble. Instead of have your variables get set inside of functions, simply return
true
orfalse
based on the test and let the calling code handle how to present the message to the user.
Example:
if(!checkHours($hours) {
print("Please choose an option from the drop down list");
}
Many of your functions exhibit the same kind of test. I see a lot of
if($var === "pleaseselect")
. Those can be made into a single function and then the fields that need validation in that manner use that one function. Changes in the future become easier when you aren't tracking down a dozen function that are doing the same thing.Some of the tests are redundant. On fields like the phone number, first you check to see if the string is empty, then you compare it to a regular expression if it is not empty. You can omit the empty test since an empty string will be caught during the regular expression test.
There are some other small things I would do differently, but again, none of that is going to affect the correct operation of your code. I can't say how much more "efficient" the code would be with changes. You would have to create a benchmark test to profile your code to tell the difference. But your code would definitely be more readable and easier to maintain.
The "is there a better way" topics like your tend to get subjective. Your question might be more geared for somewhere like Code Review. But anyway, here are a few thoughts I saw right off.
- Global variables is kind of asking for trouble. Instead of have your variables get set inside of functions, simply return
true
orfalse
based on the test and let the calling code handle how to present the message to the user.
Example:
if(!checkHours($hours) {
print("Please choose an option from the drop down list");
}
Many of your functions exhibit the same kind of test. I see a lot of
if($var === "pleaseselect")
. Those can be made into a single function and then the fields that need validation in that manner use that one function. Changes in the future become easier when you aren't tracking down a dozen function that are doing the same thing.Some of the tests are redundant. On fields like the phone number, first you check to see if the string is empty, then you compare it to a regular expression if it is not empty. You can omit the empty test since an empty string will be caught during the regular expression test.
There are some other small things I would do differently, but again, none of that is going to affect the correct operation of your code. I can't say how much more "efficient" the code would be with changes. You would have to create a benchmark test to profile your code to tell the difference. But your code would definitely be more readable and easier to maintain.
The "is there a better way" topics like your tend to get subjective. Your question might be more geared for somewhere like Code Review. But anyway, here are a few thoughts I saw right off.
- Global variables is kind of asking for trouble. Instead of have your variables get set inside of functions, simply return
true
orfalse
based on the test and let the calling code handle how to present the message to the user.
Example:
if(!checkHours($hours) {
print("Please choose an option from the drop down list");
}
Many of your functions exhibit the same kind of test. I see a lot of
if($var === "pleaseselect")
. Those can be made into a single function and then the fields that need validation in that manner use that one function. Changes in the future become easier when you aren't tracking down a dozen function that are doing the same thing.Some of the tests are redundant. On fields like the phone number, first you check to see if the string is empty, then you compare it to a regular expression if it is not empty. You can omit the empty test since an empty string will be caught during the regular expression test.
There are some other small things I would do differently, but again, none of that is going to affect the correct operation of your code. I can't say how much more "efficient" the code would be with changes. You would have to create a benchmark test to profile your code to tell the difference. But your code would definitely be more readable and easier to maintain.