Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 963021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:36:27+00:00 2026-05-16T01:36:27+00:00

I want a basic: <input type=text /> And I would like the default value

  • 0

I want a basic:

<input type="text" />

And I would like the default value to clear when the user puts in a value (kinda like this). It would be ideal if the default value returned onBlur.

I don’t want the default value to be submitted if they leave it and click submit.

I’m generating the form using Zend, and imagine my solution can fit entirely into a Zend Form Decorator.

I can’t find any existing ones, so I ask:

Do you have said decorator? Or something that will help me make one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:36:27+00:00Added an answer on May 16, 2026 at 1:36 am

    Ok, I’ve built a decorator which allows me to implement the jquery plugin Ololo posted.
    It checks to see if the element has a Label set, and if it does, defaults to that:

    require_once 'Zend/Form/Decorator/Abstract.php';
    
    class Application_Form_Decorator_DefaultEnabledInput extends Zend_Form_Decorator_Abstract
    {
        private $attribs = array();
        public function render($content)
        {
            $element = $this->getElement();
    
            if(get_class($element) != 'Zend_Form_Element_Text') throw new Exception("Application_Form_Decorator_DefaultEnabledInput only works on text fields");
    
            $element->setAttrib('type', 'text');
            $element->setAttrib('name', htmlspecialchars($element->getName()));
            $element->setAttrib('value', htmlspecialchars($element->getValue()));
    
            $attribs = '';
            $default = $element->getLabel();
            if($default)
            {
                $element->setAttrib('rel', $default);
                $element->setAttrib('title', $default);
                $class = $element->getAttrib('class');
                $element->setAttrib('class', "$class hasDefault");
                $default = "";
            }
            foreach($element->getAttribs() as $key => $val) $attribs .= "$key='$val' ";
            return "<input $attribs/>";
        }
    }
    

    It allows me to define a default value in the form object (using setLabel).

        $element = $this->createElement('text', 'suburb');
        $element->setDecorators(array('DefaultEnabledInput'));
        $element->setLabel('enter suburb here');
        $this->addElement($element); 
    

    And all I need to do then is ensure that query and plugin are included on the page, and this piece of code:

    $(document).ready(function() {
        // default values
        $('.hasDefault').each(function(){
            $(this).defaultValue();
        });
    });
    

    Then in the template, I can display the object like this:

    <?= $this->form->getElement('suburb') ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 485k
  • Answers 485k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer An example of writing t to all files: for x… May 16, 2026 at 7:37 am
  • Editorial Team
    Editorial Team added an answer Just replace: $query = "$item->".$param; by $query = $item->$param; Hope… May 16, 2026 at 7:37 am
  • Editorial Team
    Editorial Team added an answer Looks like no one is willing to answer your question.… May 16, 2026 at 7:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.