Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Improvements to the Laravel unique and exists validation rules
Oct 12, 2016 @ 14:36:42

On the Laravel News site there's a new post sharing some improvements with "unique" and "exists" validation that will be a part of the framework starting in version 5.3.18.

Validating requests in Laravel is simple with its ValidatesRequests trait that is automatically included through the BaseController.

It’s powerful and provides a lot of useful rules for common use cases. Two rules, exists() and unique(), are used to validate against data stored in your database. [...] The style of this is not the easiest to remember and it’s something you almost always have to consult the docs on.

Starting with Laravel v5.3.18 both of these rules have been simplified with an introduction of a new Rule class.

They include some code examples of using this new Rule class and how to use it right along side the current validation rule format for more complex validation needs. There's also a mention of an extra "bonus" that comes with the functionality: a conversion method for translating new rules back into strings.

tagged: laravel improvement unique exists validation rule

Link: https://laravel-news.com/2016/10/unique-and-exists-validation/

SitePoint PHP Blog:
Automated Testing of Drupal 8 Modules
May 04, 2015 @ 16:06:08

The SitePoint PHP blog has a tutorial posted talking about the automated testing of Drupal 8 modules, the components of the popular PHP-based content management system. In it author Daniel Sipos shows how to create a few tests for some functionality created in previous articles.

In this article we are going to look at automated testing in Drupal 8. More specifically, we are going to write a few integration tests for some of the business logic we wrote in the previous Sitepoint articles on Drupal 8 module development. [...] But before doing that, we will talk a bit about what kinds of tests we can write in Drupal 8 and how they actually work.

He makes use of the SimpleTest unit testing tool for PHP (versus something like PHPUnit) as it has become a standard for Drupal's own testing. He talks briefly about what SimpleTest is, how it integrates with Drupal and what kinds of tests already exist. He then gets into testing his own functionality - checking route information, that the page exists, the contents of the resulting page and the addition of a custom block plugin. He shows how to create these simple tests, extending the WebTestBase class, and checking each item on the list. He also includes an example of the resulting output of the successful testing, including time to execute and the detailed results of each test.

tagged: drupal8 automated testing tutorial simpletest introduction exists form custom plugin

Link: http://www.sitepoint.com/automated-testing-drupal-8-modules/

PHPBuilder.com:
Create a Dynamic Username Validator with PHP, MySQL and jQuery
May 11, 2011 @ 17:45:36

On PHPBuilder.com there's a new article showing you how to create a dynamic username validator with the combination of PHP, MySQL and jQuery to do some of the front end work.

One of the easiest ways to streamline the registration process is by providing the user with real-time feedback regarding username availability. This is accomplished by monitoring the registration form's username field and immediately following the user's completion of this field, rather than waiting for the user to complete all fields and submit the form. Although a seemingly complex feature, it's actually easily accomplished thanks to the powerful jQuery library.

His scripts bases its checking on an "accounts" table that holds the username and password. The javascript (jQuery) handles the "blur" event on the username text field in the form and runs a check against a backend script to see if that username exists in the database (bound parameters used for helping to prevent SQL injections).

tagged: username validation exists tutorial jquery mysql

Link:


Trending Topics: