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 6118787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:28:37+00:00 2026-05-23T15:28:37+00:00

I have a base User form that I am subclassing for each use case,

  • 0

I have a base User form that I am subclassing for each use case, i.e. Register, Edit, etc.

Some form elements are common to all use cases and for these I am using the form as an element factory, e.g. $this->addElement(‘text’, ‘first_name’, array(…)). That works fine.

For elements which are required in only some use cases, I am creating them in the base form class, but not adding them, e.g. $this->createElement(‘text’, ‘id’, array(…)). When I get to the subclass itself, that’s when I actually add these optional elements.

Now, I thought that in the subclass I would be able to simply add the element using either:

$this->addElement($this->getElement('id'));

Or

$this->addElement($this->id);

But that’s not the case. I get an exception saying I am trying to addElement(NULL).

The only way I can get the desired result is to specifically assign the create element to a member variable, then later use that variable name.

e.g. In the base form:

$this->id = $this->createElement('text', 'id', array(...));

Then in the sub class:

$this->addElement($this->id);

It seems to me that this should produce a variable name clash. If createElement is not naming my element ‘id’, what is it naming it?

EDIT

I am using the init() methods in both parent and child classes, and the child’s init() calls parent init() as its first task.

  • 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-23T15:28:38+00:00Added an answer on May 23, 2026 at 3:28 pm

    createElement does not add an element to the form, it just creates it. Unless you add it to your form, the form will not know about it. That’s why $this->id and
    $this->getElement('id') don’t work in your first example.

    In your second example, you first add the newly created element to the form (i.e. $this->id = $this->createElement('text', 'id', array(...));) and then it seems you are adding it again (i.e. $this->addElement($this->id);). I believe that there won’t be any name clash, as Zend_Form will just reassign it. Thus I think $this->addElement($this->id); is in fact not needed.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails3 form that allows the user to edit a list of
I have been support a web app that is used by a user base
I have a search form that the user can search for an Article content
I have a checkbox that is always checked, but base on user input elsewhere
I have a form for that a user fills out and submits. Once submitted
I have a custom base user control in silverlight. <UserControl x:Class=Problemo.MyBaseControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008
We have an existing WordPress install with a thriving user base. There are also
I have a Qt/C++ project and an old VB6 project. The user base might
I have 2 models: Video: class Video < ActiveRecord::Base belongs_to :user has_many :thumbnails attr_accessor
I have 2 web user controls, both inherit the same base class which extends

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.