Transverse optical mode trapping ('active guiding') in the free electron laser (FEL) is discussed via a variational approach based on classical field theory. The variational principle for the field leads to a set of simple evolution equations for the mode parameters which generalizes earlier discussion where a parabolic expansion of the interaction term was used. The method can be applied to calculate the evolution of the optical beam parameters under the interaction with an arbitrary electron beam profile. Electron beam inhomogeneities are included by using a distribution function. The equations of motions for the optical beam parameters are also derived for the full nonlinear FEL problem using the same principles.