Testing for unique value during form validation

November 7th, 2011

Let’s talk about what happens when a user signs up for a new account. He fills in his nickname, e-mail address and password and clicks Register. When validating the e-mail address you need to check for at least three things:

  1. the user provided one
  2. the syntax is all right – the e-mail is formally valid and can in fact exist (which doesn’t mean it really exists)
  3. the address hasn’t been used yet for some other account

So far not very difficult.

The tricky part comes when you allow the user to edit his profile. He can change any of the three values. When he submits the edit form the situation is one step more difficult than during registration. The e-mail address has in fact already been used – for the very user that is submitting the form. That is not the tricky part. The fun is how to get the user id when validating his e-mail address.

Read the rest of this entry »

Tweaking your forms

September 9th, 2011

Nette forms documentation lacks information about enhancing your forms while still using the default renderer. I offer here a list of solutions for the most common needs, using getControlPrototype(), getLabelPrototype(), getSeparatorPrototype() and setOption().
Read the rest of this entry »

IS NOT NULL trouble in Nette/Database

September 5th, 2011

Sooner or later, you’ll find yourself in a need of filtering out NULL values along with some other criterion. You’ve tried ->where(array('something' => $value, 'other_thing IS NOT NULL')) and got an error. I’m sure you’ve spent considerable time looking for some kind of negation that would work with NULL and I bet you’ve even tried to stick NSqlLiteral somewhere in there. I’m here to rescue you.

Read the rest of this entry »

Submitting your form to another presenter

August 31st, 2011

You probably know that you can define your form as a component in a class of its own and handle its submission in the same class. This is handy if the submission handling logic can be isolated and is independent of any presenter. But what if it needs to be a part of some particular presenter lifecycle? Then you need to force the form to submit to this particular presenter.
Read the rest of this entry »

Workaround for broken macro {form}

August 31st, 2011

If you ever tried changing your form from POST to GET with $form->setMethod(‘get’) and then render it with macro {form} … {/form} I’m sure you discovered that your submission callback doesn’t trigger. Apparently it’s difficult to resolve this in a clean way so until the Nette team finds a solution you’ll have use some sort of a hacky workaround.

Read the rest of this entry »