Tag Archive for 'sfForm'

Symfony and jQuery: sfWidgetFormJQueryMultiSelect ver 0.1

Recently i created nice and simple Symfony widget: sfWidgetFormJQueryMultiSelect. It’s really simple in use and implementation. I have used code written recently by Eric Hynds: jQuery MultiSelect Plugin w/ ThemeRoller Support and standard sfWidgetFormChoice.

Continue reading ‘Symfony and jQuery: sfWidgetFormJQueryMultiSelect ver 0.1′

Symfony 1.2 - using sfForm with jquery validation plugin - part 2

New jQuery 1.3 and its user interface have a lot of great features. But if we want to use our jQuery validation plugin with 1.3 version we need to upgrade plugin version to 1.5.1 (or higher), which is still compatible with 1.2.6. New Validate Plugin version (1.5.2) came up with some nice features like integration with UI Tabs. The following example shows a real implementation of user profile form divided in three sections.
Continue reading ‘Symfony 1.2 - using sfForm with jquery validation plugin - part 2′

Symfony 1.2 - sfForm - unsetAllExcept - better way?

It’s kind of update of function: unsetAllExcept. Lately I had a problem with unsetting some default widgets. Using for example propel and relations m-n, auto-generated forms have widgets that cannot be unsets using the current version of function - it only unset widgets by form object fields.

I think it could be useful:


<?php

  /**
   *  unset all fields except given parameters
   *
   * @param array $fields Array of fields
   */
  public function unsetAllExcept($fields = array())
  {
  	$tmp = array_keys($this->widgetSchema->getFields());

  	foreach(array_diff($tmp, $fields) as $value){

  		unset($this[$value]);
  	}
  }

?>

Symfony 1.2 and multipage form - wizard

This time i want to give you simple example about how to create multipage (wiazard) form using great Symfony 1.2 form framework. It would be simple 3 steps registeration form with validation after each step. In this example i’m using propel but it would also work great wiht Doctrine. Lets start!

First, we need to start a new project, create frontend application and multiPageForm module (from the command line prompt):

symfony generate:project multipageFormApp

symfony generate:app frontend

symfony generate:module frontend multiPageForm

Continue reading ‘Symfony 1.2 and multipage form - wizard’

Symfony 1.2 - sfForm - Yet another useful function - part 2

A couple of weeks ago i have shown you really useful example about unsetting sfForm fields - unsetAllExcept. Since that i was palying with sfForm and i found more functions that could help you working with symfony forms.

All methods shown below have to be added to BasePropelForm class (or Doctrine depending on ORM we use).

Setting single form value
There is no really simple way to set single value of field - i’m not talking about setting default value. We can call getValue on Form but not setValue. Imagine situation when we post a form and just after binding we want to set value. You can find exampe in this post.


<?php

   /**
   * Sets a value for a form field.
   *
   * @param string $field	The field name
   * @param mixed  $value	The default value
   */
    public function setValue($field, $value){

    	if(!in_array($field, array_keys($this->values))){

    		throw new sfException(sprintf('Unkown field" "%s" in "%s" object.', $field, get_class($this)));
    	}

    	$this->values[$field] = $value;
    }

?>

Continue reading ‘Symfony 1.2 - sfForm - Yet another useful function - part 2′

Symfony 1.2 - using sfForm with jquery validate plugin

Build-in symfony form validation is really great feature. Using Propel or Doctrine ORM we have simple validation by default which we can modify in simple way.
But sometimes we want something more than server side validation (later in post SSV) and then we can easliy use javascript. Client side validation (CSV) is nice and useful but we need to remember that it could be easily switched off. So SSV is always required.

Let’s begin.

I’m not going to build a whole application. I just want to show you how to create simple contact form, validate it using SSV and CSV (with jQuery) and save it.

First of all we need to create new symfony app. If we have symfony already installed on our PC, we can just create new project directory, for example sfSimpleApp and then call:


<?php

    symfomy generate:project sfSimpleApp

?>

Remember that you need to write symfony tasks in command line (on windows -cmd prompt).
As it is a simple example we are not going to configure a web server.

Continue reading ‘Symfony 1.2 - using sfForm with jquery validate plugin’

Symfony 1.2 - sfForm - Yet another useful function

Working on my new project i really need to find a good solutions for unsetting many fields in easy way. I don’t really like philosophy of unsetting each element that i don’t need. Sometimes when i add new fields to my tables i must remember to unset (all) that fields in my Forms - really irritating:) Finally i found a solution which is working really good for me - it’s nothing special but really helpfull.
Continue reading ‘Symfony 1.2 - sfForm - Yet another useful function’

Symfony 1.1 - editing uploaded file with sfForm

Lately, i a had problem with editing uploaded file.
I had an object with field “photo” that was linking to the uploaded image.
When I was editing the object and leaving the input file blank (not selecting any other image) the form saved NULL in database.

I was looking for solution on many forums and in documentation but i didn’t found anything that could help me.
Finally, i solved the problem (maybe it’s not the best way, but it’s working really good).
Continue reading ‘Symfony 1.1 - editing uploaded file with sfForm’




About me:

  • PHP programmer
  • Symfony developer
  • Zend framework developer

Categories: