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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to get data from the $form object in hook_postProcess?
Pages: [1]

Author Topic: How to get data from the $form object in hook_postProcess?  (Read 680 times)

britebyte

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 2
  • CiviCRM version: Several 3.4+, 4.1+
  • CMS version: Drupal 6, Drupal7
  • MySQL version: Several 5.1+
  • PHP version: Several 5.2+
How to get data from the $form object in hook_postProcess?
July 11, 2012, 07:28:42 am
What is the recommended way to get data from the form object in hook_postProcess?
I looked at the PHP QuickForm documentation and have been trying to use $form->exportValues() but one drawback is that custom fields have numeric suffixes which I have to deal with.

In the wiki examples I see $form->getVar( '_id' ) and I believe that this can return only the class variables of the form in question.
I see that the Core Form class has a get function but it is not clear whether this returns the submitted values, the default values or merged values.

Code: [Select]
    function get( $name ) {
        return $this->controller->get( $name );
    }

On this page I see only a function called getValue which also doesn't specify whether this returns the submitted values, the default values or merged values
http://pear.php.net/package/HTML_QuickForm2/docs/latest/HTML_QuickForm2/HTML_QuickForm2_Controller.html

I would really appreciate it if anyone can point me to a sample that addresses this idea of getting the data out.


« Last Edit: July 12, 2012, 06:07:48 am by britebyte »

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: How to get data from the $form object in hook_postProcess?
July 11, 2012, 11:25:07 am

I think exportValues is your best bet. You will need to translate from custom field id to column/table names etc

the get/set functions in Form.php basically retrieved values that you store in the session (under the form scope). It does not have anything to do with submitted/default/merged values. So basically a simple form specific storage scheme, which we typically use to store GET values from the url (so we can reuse them during the POST phase)

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

britebyte

  • I post occasionally
  • **
  • Posts: 70
  • Karma: 2
  • CiviCRM version: Several 3.4+, 4.1+
  • CMS version: Drupal 6, Drupal7
  • MySQL version: Several 5.1+
  • PHP version: Several 5.2+
Re: How to get data from the $form object in hook_postProcess?
July 12, 2012, 06:14:59 am
Lobo,
Thank you for your reply. It is nice to have validation for my approach. Since I was having to pull custom_26_7430 and custom_39_8314 using strpos and the like I thought that I must be using the wrong function.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How to get data from the $form object in hook_postProcess?

This forum was archived on 2017-11-26.