Sorry, I messed the description up.
the whole form is assigned to a variable, $form
it raises an exception "unexpected T_WHILE" on the line where the while loop is, and I don't know how to concatenate the while loop to the rest of the form.
Sorry for the confusion.