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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Custom form validation hooks and form name....
Pages: [1]

Author Topic: Custom form validation hooks and form name....  (Read 1601 times)

TheEdge

  • I post occasionally
  • **
  • Posts: 63
  • Karma: 0
  • CiviCRM version: 4.5.0
  • CMS version: Joomla 3.3.4
  • MySQL version: 5.6.17
  • PHP version: 5.4.32
Custom form validation hooks and form name....
January 17, 2012, 01:40:50 am
Hi,

I have read:

- http://wiki.civicrm.org/confluence/display/CRMDOC40/CiviCRM+hook+specification#CiviCRMhookspecification-hookcivicrmvalidate
- http://en.flossmanuals.net/civicrm/ch067_hooks/

Both mention that you need to search for the name of the form you want to validate. I created a contact form to be used as a profile (see attached). The form is called up from a simple menu item (see attached).

Looking at the generated source I see that the form is defined as:

Code: [Select]
<form action=​"http:​/​/​www.xxxxxxxx.com/​index.php?option=com_civicrm&task=civicrm/​profile/​create&Itemid=39" method=​"post" name=​"Edit" id=​"Edit" _lpchecked=​"1">​

So naturally the name of the form is "edit". However I want to make the name of the form more descriptive and under my control as I don't want to end up with edit2, edit3 etc. How/where do I do this?


Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Custom form validation hooks and form name....
January 17, 2012, 10:24:07 am
Quote
So naturally the name of the form is "edit".

I don't think so. The $formName parameter in the civicrm_validate hook doesn't correspond to the HTML name. What I would suggest is you try a simple:

Code: [Select]
echo $formName;die
in your hook. Then submit the form in question and you will see the name.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

dsdart

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 3
  • CiviCRM version: 4.4
  • CMS version: Drupal 7.25
  • MySQL version: 5.1.41
  • PHP version: 5.3.1
Re: Custom form validation hooks and form name....
January 18, 2012, 11:03:23 am
Thank you so much for posting how to find $formname - I just spent at least 45 minutes looking for this info and didn't know to put "die" after the echo!

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Custom form validation hooks and form name....
January 18, 2012, 11:49:23 am
That is the low tech way. A better way to debug is actually:

Code: [Select]
drupal_set_message( '<b>TESTING: </b><pre>' . print_r($formname,1) . '</pre>');
:)
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

dsdart

  • I post occasionally
  • **
  • Posts: 85
  • Karma: 3
  • CiviCRM version: 4.4
  • CMS version: Drupal 7.25
  • MySQL version: 5.1.41
  • PHP version: 5.3.1
Re: Custom form validation hooks and form name....
January 18, 2012, 03:20:24 pm
Cool - initially I was using the postProcess hook instead of the buildForm hook and $formname instead of $formName, but when I corrected those two things, drupal_set_message works great!
« Last Edit: January 19, 2012, 09:25:17 am by dsdart »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Custom form validation hooks and form name....

This forum was archived on 2017-11-26.