SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    An Error Occured

    Application error
    Exception information:
    Message: Zend_Form_Element requires each element to have a name

    Stack trace:
    #0 C:\webserver\htdocs\EclipseWorkspace\zfTutorial\zf-tutorial\application\forms\Album.php(9): Zend_Form_Element->__construct(NULL)
    #1 C:\webserver\htdocs\EclipseWorkspace\zfTutorial\zf-tutorial\application\controllers\IndexController.php(32): Form_Album->__construct()
    #2 C:\ZendFramework-1.8.1-minimal\library\Zend\Controller\Action.php(512): IndexController->addAction()
    #3 C:\ZendFramework-1.8.1-minimal\library\Zend\Controller\Dispatcher\Standard.php(288): Zend_Controller_Action->dispatch('addAction')
    #4 C:\ZendFramework-1.8.1-minimal\library\Zend\Controller\Front.php(936): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
    #5 C:\ZendFramework-1.8.1-minimal\library\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front->dispatch()
    #6 C:\ZendFramework-1.8.1-minimal\library\Zend\Application.php(328): Zend_Application_Bootstrap_Bootstrap->run()
    #7 C:\webserver\htdocs\EclipseWorkspace\zfTutorial\zf-tutorial\public\index.php(25): Zend_Application->run()
    #8 {main}

    Request Parameters:
    array(3) {
    ["controller"]=>
    string(5) "index"
    ["action"]=>
    string(3) "add"
    ["module"]=>
    string(7) "default"
    }

    /***********************/
    /******MyCode***********/
    public function __construct($options = null)
    {
    parent::__construct($options);
    $this->setName('album');

    $id = new Zend_Form_Element_Hidden($id);

    $artist = new Zend_Form_Element_Text('artist');
    $artist -> setLabel('Artist')
    -> setRequired(true)
    //to remove the unnecessary html and white space element use filter
    //'StripTags', return string $value without any newline control characters
    -> addFilter('StripTags')

    //'StringTrim', return string $value with chracters stripped from beginning to end
    -> addFilter('StringTrim')
    -> addValidator('NotEmpty');

    $title = new Zend_Form_Element_Text('title');
    $title->setLabel('Title')
    ->setRequired(true)
    ->addFilter('StripTags')
    ->addFilter('StringTrim')
    ->addValidator('NotEmpty');

    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setAttrib('id', 'submitbutton');
    $this->addElements(array($id, $artist, $title, $submit));

    }

    Any problems?? Help me.. i cannot figure out. Thx

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,227
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    I am unfamilliar with the Zend framework, but it looks like you need a few more setName()s eg.
    PHP Code:
    $id = new Zend_Form_Element_Hidden($id);
    ->
    setName('id');
    $artist = new Zend_Form_Element_Text('artist');
    ->
    setName('artist');
    $title = new Zend_Form_Element_Text('title');
    ->
    setName('title');
    $submit = new Zend_Form_Element_Submit('submit');
    ->
    setName('submit'); 
    Although it looks like the argument for
    new Zend_Form_Element_...()
    would use the argument for the name, maybe it's used only for an id ??

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should always develop with error reporting set to E_ALL so you can see notices. Your mistake would be obvious

  4. #4
    SitePoint Member
    Join Date
    May 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My setting in php.ini is "error_reporting = E_ALL | E_STRICT", does it correct? Correct me if i'm wrong..thx

  5. #5
    SitePoint Member
    Join Date
    May 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know the problem already, $id = new Zend_Form_Element_Hidden($id);, my $id, this param do not have value. So this error may occur. thanks guy, give me hints

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, what makes you think the variable should have a value if you have not defined this variable?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •