Cestfait.ch

  • Home
  • Drupal
  • PHP 5
  • Jquery
  • Web Dev
  • Sys admin
  • Logiciels libres
  • Videos
  • Divers
  • Nous contacter
  • Mon c'est fait!
Home

Drupal and Zend, form validate :)

Submitted by Sir Squall on Mon, 04/19/2010 - 14:02

Ce qui est cool sur drupal c'est que pour crée des formulaires c'est super simple, et c'est qui est cool sur zend ce que de valider un formulaire c'est super simple, alros ce qui est classe c'est quand on a drupal et zend bah on peut faire des truc qui on de la gueule :

/**
 * form 
 */
function myzend_form($form_state){
 
  $form['mail'] = array(
    '#type' => 'textfield', 
    '#title' => t('mail'), 
    '#default_value' => variable_get('mail', null),
    '#description' => t('Entrer votre adresse mail'),
    '#zend' => 'Zend_Validate_EmailAddress',
  );
 
 
  $form['submit'] = array(
    '#type' => 'submit', 
    '#value' => t('Save'), 
  );
 
 
  return $form;
}
 
/**
 * Validate
 */
function myzend_form_validate($form,&$form_state){  
 
  //automated validation zend
  foreach($form as $key => $value){
    //check if have a zend validation    
    if(!is_array($value) || !isset($value['#zend'])){
      continue;
    }
    //get the value
    $val = $form_state['values'][$key];
 
    //load the class zend
    if(zend_initialize($value['#zend']) && zend_initialize('Zend_Validate_Abstract')){
 
      //initialize the validator
      $validator = new $value['#zend'](); 
 
      //check if is the good instance
      if(!$validator instanceof Zend_Validate_Abstract){
        form_set_error($key,t('Erreur'));
      }
 
      //validate
      if (!$validator->isValid($val)) {
        foreach ($validator->getMessages() as $messageId => $message) {
          form_set_error($key, t("Validation failure '$messageId': $message"));
        }
      }
    } 
  }
}

C'est fait !!!

0
Log in to vote
Your rating: None Average: 5 (1 vote)
  • Login or register to post comments
  • Share this
Tags:
  • Divers
  • drupal
  • Zend

User login

  • Create new account
  • Request new password
  • Sign in with Twitter

Translate

Sondage

Wich OS ?

Submitted by Sir Squall on Wed, 05/11/2011 - 10:07
  • Login or register to post comments

Recent comments

  • Usefull post. I bookmark this
    2 weeks 2 days ago
  • Usefull post. I bookmark this
    2 weeks 2 days ago
  • Arf, je suis à l'armée!
    25 weeks 3 days ago
  • hahaha c'est juste! Il n'y a
    31 weeks 6 days ago
  • yeah comme sa fait plaisir de
    32 weeks 1 day ago
  • wouahou merciii :-) !
    35 weeks 6 days ago
  • J'y réponds aujourd'hui ici
    36 weeks 1 hour ago
  • Salut, court article mais
    36 weeks 1 day ago
  • Oktoberfest power!!!
    40 weeks 6 days ago
  • yep je vais faire un petit
    42 weeks 4 days ago

Tags

cropping Divers Drupal drupal Drupal 7 emacs epsacrop firefox git Google Images jquery Jquery karmic koala La phrase du jour Lausanne Logiciels libres mysql PHP 5 php 5.3 Sys admin ubuntu Web Dev Zend
more tags

Popular content

Today's:

  • Drupal 6, Patch Master/Slave
  • 8ème Forum eCulture - ERACOM - 4 septembre 2009
  • Lucid lynx, html validator firefox 3.6 C'est possible!
  • It is finally here!
  • Drupal 7 effet avec les jquery.ui.dialog sur Drupal 6 !
  • Google chrome pour mac
  • Nice card
  • Coyote Ugly @ Winterthur
  • [Drupal 6] textarea avec wysiwyg
  • [Drupal] créer des functions javascript a la volée!

All time:

  • Dries Keynote DrupalCon Paris 2009
  • Drupal 7 effet avec les jquery.ui.dialog sur Drupal 6 !
  • Drupal bridge zend yeah !!
  • Jquery JSON en _POST
  • Drupal and Zend, form validate :)
  • [Drupal] Lightbox avec une gmap! yeah
  • Jquery slider c'est de la bonne !!!
  • [Drupal] Domain Access & memcache sa donne quoi ?
  • viportuguese-shop.com
  • Node Import et Taxonomy CSV

Last viewed:

  • C'est un peu court jeune homme
  • MySql order by rand() very slow!
  • EPSA Crop disponible en 1.0
  • Clean les vilains tag word
  • Buell lightning city X
  • Office automation in php
  • Fautes d'orthographes
  • Disable post with jquery!
  • Autocomplete jquery
  • Strange requests

Twitter

Latest Articles

Derniers liens publiés

  • Cloudflare et Dropbox nommés Technology pioneers
    http://techcrunch.com/2011/09/01/cloudflare-dropbox-palantir-and-kickstarter-named-technology-pioneers-by-the-world-economic-forum/
  • Apprend le javascript en t'amusant
    http://www.codecademy.com
  • EPSACrop sur Drupal 7
    http://www.aswissidea.org/
  • Drupal solr attachement intégration
    http://tika.apache.org/
  • CloudFlare + Mollon
    http://www.cloudflare.com/

Pub

Google gadget

Add to Google

Facebook page

jiwa

all good song

Partenaires

Cyber Warfare

Drupal Factory

I love Smashing Magazine!
Fervens Drupal theme by Leow Kah Thong. Designed by Design Disease and brought to you by Smashing Magazine.