Virtual Mechanics: Community Forums and FAQs
Virtual Mechanics: Community Forums and FAQs
Web General Discussion
PHP Validation|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Working Mechanic |
Hi. In the FormMail tutorial there is no validation of the data in the example. Can anyone tell me where I can find some code to validate the fields? Thanks.
KP> P.S. Perhaps in the next version of SiteSpinner they can put a proper complete example with some validation |
||
|
|
Honorary 'Aussie' Mechanic |
Hi Exquistus,
First of all, I don’t think the next version of SS will include any advanced PHP scripting. PHP is a complicated stand alone server side coding language, and is far too advanced to be included in any web developing software. Besides that, some web hosts use ASP or Perl instead of PHP. So, you can’t expect SS to create tutorials on all. You are lucky that your host supports PHP and that SS has given you a starting point. If you do an advanced search with Google, using form validation "PHP" as a search criteria, it will bring up about 1,650,000 results. Good luck. The criteria that people want is so varied, it is difficult to answer your question directly. There are many programs out there (I suppose, some free) that will develop forms and create the required PHP script for you. Unlike Larry, who is a proficient code developer and writes his own, I prefer to use a program where you can develop your own form in any format, such as SS, then dump that form into a program, set all of your criteria, and it creates the PHP code for you. Clever buggers, aren’t they. As a starter, the program that I have used for years is Forms To Go There are of course other programs available such as Web Form Builder, but they require building your form within their own program. Using SS with CSS, it’s a breeze to design exactly what you want, then dump the page into a program such as Forms to Go, and create your final PHP code. |
|||
|
|
Guru 'Geezer' Mechanic |
While PHP can be used to validate the form, it is not quite as simple as you may think. For one thing the PHP would have to be told what fields of your form require validation, and if you require data-type validation (i.e, dates, phone numbers, zip codes, etc), the PHP script would also need to know which fields need this type of validation. This adds a level of complexity to the simple SendMail form in the tutorial. Then you have to figure out how to have the PHP script inform the visitor of the error and return back to the page with the form, hopefully placing the cursor inside the field so a correction can be made.
With a simple form like that used in the Form Mail tutorial, validation is best performed using javascript when the Submit button is clicked (the onsubmit event). This allows you to check the values before the visitor leaves your page. There are several examples and tutorials of javascript form validation on the web. A good starting point is http://www.w3schools.com/jS/js_form_validation.asp |
|||
|
|
Working Mechanic |
Hi again. Thanks for the help. I have a couple other questions now. In the SiteSpinner tutorial one example starts with:
<?php and the other one starts with: <? What's the difference? I know I have to upload the .php file to my host but my other question is where in SiteSpinner would I put the javascript? Thanks again. KP> |
|||
|
|
Honorary 'Aussie' Mechanic |
Some servers will not recognize PHP without the leading <?php where as all servers will, so it is good practice to always use it.
Javascript is placed into a code object, and ,depending on it’s use, can be placed in either the body or head sections. |
|||
|
| Powered by Eve Community |
| Please Wait. Your request is being processed... |
|

