From anthony at dating2p0.com Wed Jul 14 17:46:42 2010 From: anthony at dating2p0.com (Anthony Wlodarski) Date: Wed, 14 Jul 2010 17:46:42 -0400 (EDT) Subject: [zendframework] =?utf-8?q?Disparity_between_=24=5FPOST_and_=24for?= =?utf-8?q?m-=3EgetValues=28=29_in_Zend_Framework=2E?= Message-ID: <1279144002.254618358@192.168.2.230> I have been scratching my head on this one. I have a form that has many elements. One of them is a listing of blocked users. I feed the blocked users in after other form elements have been created with the following function: $form->setBlockedUsers($this->userModel->get_blocked_users()); Function body: public function setBlockedUsers($blocked_users = null) { $element = new Zend_Form_Element_MultiCheckbox('blocked_users'); $element->setLabel('Remove the following users from your blocked list by selecting the checkbox.'); $element->addMultiOptions($blocked_users); $this->addElement($element); } Now when I go to get the values I have a generic validation method from Zend Framework, then I feed the model the form values as necessary and off it goes to the database: if($this->getRequest()->isPost()) { if($form->isValid($_POST)) { // we are going to update the users settings with the values from the form if($this->userModel->updateAccountSettings($form->getValues())) { Inside of of the function call I am looking for $values['blocked_users'] based on the code in setBlockedUsers, however I have learned that the array key is not even there. I did a quick debug output of the values and this is what I get: Array ( [match_frequency] => 1 [reverse_match_frequency] => 1 [features_event] => 1 [message_event] => 1 [wink_event] => 1 [favorite_event] => 1 [not_interested_event] => 1 [profile_match_event] => 1 [allow_chat_requests] => 1 [blocked_users_abc] => Array ( [0] => 1 [1] => 2 ) [edit_user_settings_submit] => Update Account Settings ) Array ( [match_frequency] => 1 [reverse_match_frequency] => 1 [features_event] => 1 [message_event] => 1 [wink_event] => 1 [favorite_event] => 1 [not_interested_event] => 1 [profile_match_event] => 1 [allow_chat_requests] => 1 ) The first array is $_POST and the second array is $values. I have looked at the code multiple times. Created the array manually without seeding it with calls from the database, removed the field from the function and put it into the Zend_Form init() function. I even looked at setIgnore() and made sure it was false. I can't think of anything else at this point. Any ideas or suggestions? Anthony Wlodarski Lead Software Engineer [http://www.dating2p0.com] Dating 2.0 646 285 0500 x217 anthony at dating2p0.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From anthony at dating2p0.com Wed Jul 14 18:26:09 2010 From: anthony at dating2p0.com (Anthony Wlodarski) Date: Wed, 14 Jul 2010 18:26:09 -0400 (EDT) Subject: [zendframework] =?utf-8?q?Disparity_between_=24=5FPOST_and_=24for?= =?utf-8?q?m-=3EgetValues=28=29_in_Zend_Framework=2E?= In-Reply-To: <1279144002.254618358@192.168.2.230> References: <1279144002.254618358@192.168.2.230> Message-ID: <1279146369.650428349@192.168.2.230> Well I figured out my own issue. It was a logic and order of evaluation issue. Basically the field is dynamically populated if there is no $_POST request already waiting. When the $_POST request exists based on the order of evaluation the dyanmic form field is never added and therefore never added ot the Zend_Form objects list of validators. -Anthony -----Original Message----- From: "Anthony Wlodarski" Sent: Wednesday, July 14, 2010 5:46pm To: zendframework at lists.nyphp.org Subject: [zendframework] Disparity between $_POST and $form->getValues() in Zend Framework. I have been scratching my head on this one. I have a form that has many elements. One of them is a listing of blocked users. I feed the blocked users in after other form elements have been created with the following function: $form->setBlockedUsers($this->userModel->get_blocked_users()); Function body: public function setBlockedUsers($blocked_users = null) { $element = new Zend_Form_Element_MultiCheckbox('blocked_users'); $element->setLabel('Remove the following users from your blocked list by selecting the checkbox.'); $element->addMultiOptions($blocked_users); $this->addElement($element); } Now when I go to get the values I have a generic validation method from Zend Framework, then I feed the model the form values as necessary and off it goes to the database: if($this->getRequest()->isPost()) { if($form->isValid($_POST)) { // we are going to update the users settings with the values from the form if($this->userModel->updateAccountSettings($form->getValues())) { Inside of of the function call I am looking for $values['blocked_users'] based on the code in setBlockedUsers, however I have learned that the array key is not even there. I did a quick debug output of the values and this is what I get: Array ( [match_frequency] => 1 [reverse_match_frequency] => 1 [features_event] => 1 [message_event] => 1 [wink_event] => 1 [favorite_event] => 1 [not_interested_event] => 1 [profile_match_event] => 1 [allow_chat_requests] => 1 [blocked_users_abc] => Array ( [0] => 1 [1] => 2 ) [edit_user_settings_submit] => Update Account Settings ) Array ( [match_frequency] => 1 [reverse_match_frequency] => 1 [features_event] => 1 [message_event] => 1 [wink_event] => 1 [favorite_event] => 1 [not_interested_event] => 1 [profile_match_event] => 1 [allow_chat_requests] => 1 ) The first array is $_POST and the second array is $values. I have looked at the code multiple times. Created the array manually without seeding it with calls from the database, removed the field from the function and put it into the Zend_Form init() function. I even looked at setIgnore() and made sure it was false. I can't think of anything else at this point. Any ideas or suggestions? Anthony Wlodarski Lead Software Engineer [http://www.dating2p0.com] Dating 2.0 646 285 0500 x217 anthony at dating2p0.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From alan at alanseiden.com Wed Jul 21 16:00:48 2010 From: alan at alanseiden.com (Alan Seiden) Date: Wed, 21 Jul 2010 16:00:48 -0400 Subject: [zendframework] Meet and Greet, Tues, July 27 Message-ID: <4C4751F0.70301@alanseiden.com> July's NY-PHP SIG meetup for Zend Framework Join us at TGI Friday's after the regular NY-PHP User Group meeting (http://www.nyphp.org) to meet others in the Zend Framework community. We will gather at approximately 8 PM at TGI Friday's at 56th and Lex. In addition, we recommend the regular NY-PHP meeting beforehand at 6:30, for Hans Zaunere's presentation about PHP 5.3. Register for Hans's talk at http://www.nyphp.org if you can attend his talk. Either way, we hope to see you for our ZF Meetup. When: Tuesday, July 27, 2010, 8PM, after the regular NY-PHP meeting Where: TGI Friday's at 56th and Lexington, New York City Learn more here: http://www.meetup.com/ZendFramework-NYCmetro/calendar/14171936/ Hope to see you there! Alan -- Alan Seiden Specialist, PHP for IBM i Zend Certified Engineer for Zend Framework PHP/i solutions, Strategic Business Systems, Inc. alan at alanseiden.com | 201-327-8746 x144 | blog/articles: alanseiden.com