CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Added Form Elements Not Being Passed on Submit
Pages: [1]

Author Topic: Added Form Elements Not Being Passed on Submit  (Read 1105 times)

qjensen

  • I post frequently
  • ***
  • Posts: 141
  • Karma: 11
    • Scaled Solutions
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Added Form Elements Not Being Passed on Submit
January 26, 2011, 11:17:57 am
OK - I hate to post so often, but I am running into some issues with my update to 3.3.3.

I have created a customized version of the price option edit form and added a multi-select list to it. It displays correctly, but when the form is submitted the list is not in the elements of the form. I can see it in the $_POST variables when I debug, but it isn't a part of the form object. Previously I was able to get the value from the form object. Is this new behavior?

Thanks for your (added) help,
Quint Jensen
Web Developer
Scaled Solutions
--" Remove the 'I want you to like me' notes from your forehead and place them where they truly will do the most good -- on your mirror!" Author Unknown

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Added Form Elements Not Being Passed on Submit
January 26, 2011, 11:23:39 am

The upgrade hould not have changed the below stuff. Can you cut-n-paste the relevant parts of your hook code and/or jump onto IRC and use pastebin there. might make it  lot easier and quicker

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

qjensen

  • I post frequently
  • ***
  • Posts: 141
  • Karma: 11
    • Scaled Solutions
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Added Form Elements Not Being Passed on Submit
January 26, 2011, 11:49:33 am
IRC appears to be down right now, so I'll post here.

This is the code I have been using to add the list to the form.
Code: [Select]
if($formName == 'CRM_Price_Form_Option' && $action == 'update'){
//generate list of memberships to add to form
$group_list = getGroupList();
//get any acl's that already exist
$oid = $form->getElement('optionId')->getValue();
//no oid means this price option is being added
if($oid){
  $groups_selected = getAcl($oid);
}
// set default values
$form->setDefaults(array('groups'=>$groups_selected));
$form->addElement('select','groups','Groups',$group_list);
$element = $form->getElement('groups');
if(!$oid){
  $element->updateAttributes(array('disabled'=>true));
}
$element->setMultiple(true);
}

In my postProcess hook I have the following code

Code: [Select]
function memberprice_civicrm_postProcess( $formName, &$form ){
  $action = $form->getVar('_action');
if($formName == 'CRM_Price_Form_Option' && $action == CRM_Core_Action::UPDATE){
$price_option_id = $form->getElement('optionId')->getValue();
  $acl_group_id=$form->getElement('groups')->getValue();

I get an error at
Code: [Select]
$form->getElement('groups')->getValue() - Non existent html element 'groups'.

In debug mode I can see that the submitted form in postProcess does not have the select list that I added in buildForm.
Quint Jensen
Web Developer
Scaled Solutions
--" Remove the 'I want you to like me' notes from your forehead and place them where they truly will do the most good -- on your mirror!" Author Unknown

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Added Form Elements Not Being Passed on Submit
January 26, 2011, 12:33:45 pm

can you eliminate the

&& $action == 'update'

and see if that works

if so, can you add:

&& $action == CRM_Core_Action::UPDATE

(and set $action previously) and see if that works

thanx

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

qjensen

  • I post frequently
  • ***
  • Posts: 141
  • Karma: 11
    • Scaled Solutions
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Added Form Elements Not Being Passed on Submit
January 27, 2011, 02:22:28 am
OK, that worked but I don't understand why. I was setting $action by getting it from $_GET since I wasn't able to get it from $form at the time. As I stepped through the code I saw the list added to the form (it was actually in the $form object in the debug window) and it displayed correctly.

I changed to getting $action from the $form var as you instructed in a previous post, and switched to using CRM_Core_Action::UPDATE as you asked, and now the list is added to the form AND it is submitted and handled correctly in postProcess. I guess I assumed that if it was being added to the form and displayed it would be there to be processed. As I write this I am literally switching between the two ways of checking the $update variable, stepping through it in debug mode and the code path doesn't change, only method of getting and checking $update. Can you let me in on the secret :)

Thanks for your help and explanation.
Quint Jensen
Web Developer
Scaled Solutions
--" Remove the 'I want you to like me' notes from your forehead and place them where they truly will do the most good -- on your mirror!" Author Unknown

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Added Form Elements Not Being Passed on Submit
January 27, 2011, 08:04:39 am

basically action is one of the few variables that we "munge" when we store it in the session

So in the GET we have a string: "update" but we store it as action=2 (and all the code knows that action 2 means UPDATE)

when the form is submitted, which calls the buildForm hook again, there is no action in the GET params and hence the condition was failing. But the form always knows what the action is and hence it worked

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Added Form Elements Not Being Passed on Submit

This forum was archived on 2017-11-26.