2

I'm updating a form in my zend project it's pretty basic. After updating the form to use a <button type="submit"> tag it's not posting the form.

Does not work <button type="submit" name="Save">Continue</button>

Works <input type="submit" name="Save" value="Next">

Part of the code in the controller which throws the error is below, why is $value = trim($value); showing up empty when I post the form? All my fields and form action is correct I've tested everything and it's come down to the submit button type being the problem. Thanks

    $userSess = new Zend_Session_Namespace('Default');
    if (!$this->getRequest()->isPost()) {
    $this->_helper->redirector('index','welcome');
}
$postData = $this->_request->getPost();
//validating form data, if empty data comes, redirect with err msg
    foreach($postData as $key => $value) {
        $value = trim($value);
        if($value == "") //if empty field submitted, redirect back with invalid msg
        $this->_helper->redirector('index','welcome',null,array('err'=>'Please Fill in all details'));
    }

1 Answer 1

4

Use this:

<button type="submit" name="Save" value="Next">Continue</button>

You have forgotten value attribute. According to your code, if any input field has empty value, you execute redirect. In your case, input field Save does not have a value (when you use <button> tag)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that worked. I thought the value in the input was only being used because it was an input value vs a button which had the value set between the tags. And that the values the code was looking for was data imputed into each field in the form.
Nothing to do with that, if value omitted, the text content will be used as value (+ older IEs doesn't use value attribute at all)

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.