Zend Form – custom decorators

28 April 2008

So I’m learning PHP and Zend Framework and MVC stuff. And I just figured out how to do a custom decorator on Zend_Form to change the way the form is written to HTML. The default puts each element label and input box into dd and dl tags. I just wanted to put each element in a div, with the input box on the same line as the label. There may be better ways to do this, but this is what I put in the IndexController.php file:

$form = new Zend_Form(array(
    'elementDecorators'=>array(
       'ViewHelper',
       array(
          'Description',
          array(
             'tag'=>'div',
             'class'=>'help'
          )
       ),
       'Errors',
       array('Label'),
       array(
          'HtmlTag',
           array(
              'tag'=>'div',
              'class'=>'field'
           )
        )
    ),
    'decorators'=>array(
        'FormElements',
        array(
          'HtmlTag',
          array('tag' => '<div>')
        ),
        'Form',
     ),
    'method' => 'post',
    'action' =>'/url/to/form',
    'elements' => array(
        'name' => array('text', array(
            'label' => 'Name:'
        )),
        'subject' => array('text', array(
            'label' => 'Subject:'
         )),
        'submit' => array('submit', array(
            'label' => 'Add',
        ))
    ),
 ));
 $form->submit->removeDecorator('Label');
 return $form;
}
 public function formAction()
 {
      $this->view->form = $form;
 }

The $form->submit->removeDecorator(‘Label’) bit removes the extra ‘Add’ from the submit button.

Then you just put
echo $this->form;
in your form.phtml

(This form does nothing)

This results in HTML like:

<form method="post" action="/route/to/form">
   <div>
      <div class="field">
         <label for="name" class="optional">Name:</label>
         <input type="text" name="subject" id="subject" value="">
      </div>
      <div class="field">
          <label for="subject" class="optional">Subject:</label>
          <input type="text" name="subject" id="subject" value="">
      </div>
      <div class="field">
           <input name="submit" id="submit" value="Add" type="submit">
      </div>
   </div>
</form>

Instead of the default dd and dl layed out form.

Blog tag / eight random things

I got tagged (by Rowan Stanfield) in a game of blog tag a while ago and I only just got around to doing this. So here’s 8 random things about me.

1. I’ve done a round-the-world trip twice. My favourite cities have been Melbourne, San Francisco, Seattle, Vancouver and New York (and of course Brighton!). New Zealand is over-rated. New Delhi (and surrounding area) is depressing. Hawaii is full of tourists. Fiji is beautiful but full of honeymooners and Christians.

2. I am impressed by films involving aliens, robots, zombies, gore, explosions, and big guns.

3. I am scared of the dark. Possibly due to over exposure to things in point 2.

4. I am constantly looking for a new job, even when I like my current one. I think I like to keep up to date with what opportunites exist, and how much I *could* earn.

5. despite point 4, OKCupid.com tells me I am unambitious. I think that’s because I put lots of things before money/ownership, but I think OKCupid has ambition confused with materialism. I’ve been on OKCupid for years and years. It’s good for self-obsession but nearly everyone on there is really ugly.

6. I play World of Warcraft. My main character is currently level 45. I don’t obsess over it, but have been known to play for about 5 hours in a row on occasion. Even though I find it repetitive, it’s quite a good way to unwind. When I was about 16 I had to ban myself from playing Doom because I started to tense up when approaching a corner in real life, envisioning flaming skulls coming at me from the other side. I went cold turkey on it.

7. I’m totally fat-ist. I think people should know when to stop eating and just not be fat. If you eat too much, you are greedy and weak. It’s a sign of lack of self control. I just don’t like looking at fat people. I know this is hypocritical because I’d quite like to gain about a stone and I find that hard. Oh well, I’m a hypocrite and a bad person.

8. I did a Biology degree and specialised in evolution and mating behaviour. So I know lots of strange facts about slug mating rituals, field mouse penises and how environmental resources relate to monogammy/polygammy. I do tend to apply my knowledge of evolution to understanding human behaviour, relationships and flirtation.

OK so now I have to tag 8 people and they can do the same if they like (but they don’t have to):

Jeremy Keith (adactio)

Christine Hennessey (evilolive)

Shannon Ritter (micala)

Dave Stone (builtbydave)

Josh Russell

Trevor May (antikewl)

Richard Bacchus (dubnacious)

Paul Burgess (delarge)

Andy Budd

Sausages: Freestyle LDN art show in York

I’m going to be exhibiting six of my illustrations at Freestyle LDN art show in York on 26th April 2008. Here’s my latest illustration of a man eating a sausage. It’s from a tinned sausage advert I saw in Prague last summer, and the image was apparently an original 1917 illustration. I’ve tweaked it a bit of course, and vectorised it. Another version of the ad has spit dribbing from his chin. Lovely. I also like how dainty his fingers are.

Blogged with the Flock Browser

Tags: , , , ,

Facebook privacy with friend lists

14 April 2008

You can now basically do anything you’d ever want with the new privacy controls within Facebook. So, if you want to make a list of ex-boyfriends and stop them seeing certain information about you, you can! Or, if you make a list of hotties, you can make a special photo album just for them!

Lists kind of work like groups as far as communication is concerned, but at the moment people don’t know what lists they’ve been put into by other people – they are for an individual to group/categorise their friends, for their own purposes.

I only hope the ways I’ve categorised my friends within Facebook never gets revealed to my friends!

Facebook privacy with friend lists

Interestingly, this blog suggests that you can “shield your friend list from any or all of your friends and networks”, whereas this blog says the opposite, that “Friend lists are “private groups” of your friends. No one can see the friend lists you make.”  Hopefully the first blog wasn’t talking about these new friend lists that a user creates and names accordingly, but was talking about a user’s main, complete, Facebook friend list.  If a user’s main Facebook friend list is called a friend list and the lists a user creates to organise their Facebook friends is called a friend list, talking about this could get pretty confusing.

 Page 18 of 31  « First  ... « 16  17  18  19  20 » ...  Last » 
Dead #butterfly #taxidermyBiologyTea and pastryTom being BritishSam and teacupClaudia becomes British partyWell this can sod offMoustache Christmas cracker
Powered by Wordpress   |   Lunated designed by ZenVerse