Beware of these mistakes while coding in PHP-Part 2

Beware-of-these-mistakes-while-coding-in-PHP

Mistake 2: Forgetting to unset the reference variable after the loop.

In the previous blog of the series we started with the isset function mistake and I have promised to post about the next mistake which is leaving dangling array references after foreach loop.

While working with arrays, we need foreach to iterate over arrays. In some case, we might be just displaying each array element while iterations but in some case, we might need to manipulate or operate on each element. When there is a case, where we need to operate on each element, using references in foreach loops can be useful. See below code snippet.

Continue reading
0
  979 Hits
  0 Comments
979 Hits
0 Comments

Beware of these mistakes while coding in PHP

Beware-of-these-mistakes-while-coding-in-PHP

As a PHP developer, I am sure we all write some lines of code every day where we use library functions, creates new functions, Writes for, for each loop and also we use some statements and many more things that we need to do for solving a problem by PHP. Do we use the right library functions in the right place? Do we write correct loops? In my opinion, we do common mistakes while doing these things, so what are those mistakes and how to get rid of it, what will be the solutions for it? These are the common questions that arise in every PHP developer’s mind while coding.  

I will be covering these common mistakes and their solutions in a series of blogs, Let’s start with the first blog of this series.

Misunderstandings of isset()

As the name suggests, isset() function returns true if the item exists and returns false if the item does not exist but it returns false for null values too. This turns into a problematic behavior in some cases and becomes a common source of problems.

Continue reading
0
  1830 Hits
  0 Comments
1830 Hits
0 Comments

Some JavaScript code snippets in Joomla worth keeping in your stash

Some-Joomla-Javascript-Code-Snippets-Worth-Keeping-in-your-Stash

In this blog, I will be explaining some JavaScript snippets which are very useful while developing extensions in Joomla. Let’s start one by one.

Continue reading
1
  3815 Hits
  0 Comments
3815 Hits
0 Comments

Difference between let and var keyword in JavaScript

Difference-between-Let-and-Var-in-JS

When any developer is working in JavaScript, He/She often uses let, var keywords. Most of us use it randomly as there has been a lot of confusion regarding the use of let and var in JavaScript. So, I am trying to clear most of the confusion by presenting one example.

So let’s check the difference between `let` and `var `with one example:

Continue reading
0
  6121 Hits
  0 Comments
6121 Hits
0 Comments

Using custom field of jform create textcounter

Using-custom-field-of-jform-create-textcounter-1

Joomla already has powerful form management libraries - jform, supported by jfield. There is plenty of built-in field types (text, textarea, integer, file, calendar and several more). However, once in a while you come across a special field that is not present. Or maybe extending the existing field types to add more features.

These are perfect candidates for creating your own JFields. The JField class is very easy to understand, and using the same you can create any kind of simple or complex fields. Bear in mind that while the JField class will render your field, it's up to your model to save the data.

In a recent project, I had to create a text field with a character limit and a  character counter. My earlier thought was to include a piece of javascript, but I soon realized that this was a good opportunity to create a reusable field which supports the above. So today I will be explaining how to create your own JFields through an example of the character counter field.

Continue reading
1
  2121 Hits
  0 Comments
2121 Hits
0 Comments

Using sub-forms to create repeatable fields

Using-sub-forms-to-create-repeatable-fields

Forms are everywhere on the web. From a simple sign up form to complicated application forms you’ve seen various forms with varying validation and fields. A very popular way to ask users to input multiple values for similar data is to use the “Add More” type field where the user can add any number of entries. Examples are Educational Qualification, Previous Employment History etc.

Joomla too supported the add more fields natively, by use of the repeatable element. However it had a few limitations

  • The sub fields show up in a popup, and not inline
  • It’s not easy to customise the layout of the popup

We’d tried to overcome these in a recent project by improving the repeatable field, but while we were doing that we realised that Joomla 3.6 has solved this in a much better way! Welcome “sub forms”. This provides a way to use JForm XML inside existing forms, by way of including another XML in lieu of a field in the parent XML. With sub-forms you can -

Continue reading
11
  23018 Hits
  0 Comments
23018 Hits
0 Comments