1

I would like to make my Zend_Form_Element_Text dynamic, i.e it will accept different input name.

I have this:

 $email = new Zend_Form_Element_Text('email');

It create an input with 'email' as the name:

 <input name="email" id="email" size="20" maxlength="100" placeholder="Email" class="input" type="text">

But sometimes I receive some external POST request and their input name field are different, like this:

 <input name="login_Email" id="email" size="20" maxlength="100" placeholder="Email" class="input" type="text">

Can you please guide me how I can do that?

1 Answer 1

1

In your controller, I guess you have something like this to get POST variables:

if ($this->getRequest()->isPost()) {
    $formData = $this->getRequest()->getPost();

    if ($form->isValid($formData)) {
    ....

So you can test each POST variable, if it matches than 'email' and not equals to 'email', you can create a new email variable POST

if ($this->getRequest()->isPost()) {
    $formData = $this->getRequest()->getPost();

    foreach($formData as $name => $value){      
        if ($name != 'email' && preg_match("/email/i", $name))
            $formData['email'] = $value;
    }
    if ($form->isValid($formData)) {
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.