Running Drupal 7.8, PHP 5.2

After enabling module, receive error:

DatabaseSchemaObjectExistsException: Table contact_fields already exists. in DatabaseSchema->createTable() (line 652 of /home/alguire/public_html/includes/database/schema.inc).

Then, upon visiting the manage fields tab I get 12 errors, including:

Notice: Undefined index: #title in _set_core_fields() (line 361 of ... /sites/all/modules/contrib/contact_field/contact_field_admin.inc).
Notice: Undefined index: #required in _set_core_fields() (line 367 of ... /sites/all/modules/contrib/contact_field/contact_field_admin.inc).

Comments

beautifulmind’s picture

Status: Active » Postponed

Hello,
Thank you for your concern and using the module.
If you have checked with the release note, its advised that not to use this release. You can examine the code, howerver.

Regards.

freeform.steph’s picture

Thanks for the quick response - indeed I should have read the notes first!

jonathan_hunt’s picture

I ran into the same error above.

Some suggestions:
1. Remove unnecessary @author attributions for each function.
2. Add useful documentation regarding each function rather than restating the function name.
3. Adhere to Drupal code standards (e.g. whitespace, no tabs, etc.)
4. Many variables seem to have meaningless prefixes, e.g. ss__, am__ etc. For example, _get_fields() makes more sense if $om__result is renamed to $field and $am__settings is renamed to $field_settings.
5. Be careful with your function naming. Names like _get_fields() way too generic IMHO and will result in collisions if other modules are also loose with naming. Use _contact_field_get_fields() or similar to avoid polluting global namespace.
6. Operations link paths should map to admin/structure/contact/ instead admin/build/contact/

Some changes:
a. t() is default title callback so you don't need to specify it.
b. I suggest suffix any form definition functions with form (e.g. contact_field_form)
c. Run the form through a theme function - do your table-based layout in the theme function (see menu_overview_form and theme_menu_overview_form and refer to http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ad... where it is recommended that this functionality be added via the theme layer)
d. db_result() is not available in D7.

diff --git a/modules/contact_field/contact_field.module b/modules/contact_field/contact_field.module
index a2915f3..ef568bd 100755
--- a/modules/contact_field/contact_field.module
+++ b/modules/contact_field/contact_field.module
@@ -21,10 +21,9 @@ function contact_field_menu() {
   $item = array();
   $item['admin/structure/contact/manage'] = array(
     'type' => MENU_LOCAL_TASK,
-    'title' => "Manage fields",
-    'title callback' => 't',
+    'title' => 'Manage fields',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('contact_field_list_field'),
+    'page arguments' => array('contact_field_form'),
     'access arguments' => array('administer site configuration'),
     'file' => 'contact_field_admin.inc',
     'file path' => drupal_get_path('module', 'contact_field'),
@@ -71,7 +70,18 @@ function contact_field_menu() {
   return $item;
 }
 
-
+/**
+ * Output contact field management form via theme (to wrap contact fields in a table with draggable weights).
+ * Implements hook_theme().
+ */
+function contact_field_theme() {
+  return array(
+    'contact_field_form' => array(
+      'file' => 'contact_field_admin.inc',
+      'render element' => 'form',
+    ),
+  );
+}
 
 /**
  * Implementation of hook_form_alter
@@ -281,21 +291,15 @@ function _contact_field_allowed_tags() {
        return array('a', 'b', 'big',  'code', 'del', 'em', 'i', 'ins',  'pre', 'q', 'small', 'span', 'strong', 'sub', 'sup', 'tt', 'ol', 'ul', 'li', 'p', 'br', 'img');
 }
 
-
 /**
- * _get_field_type
- * 
- * Return type of the field
- * 
- * @param string $ss__field_name
- * @author Bhavin H. Joshi <bhavinjosi@joshics.in>
+ * Return type of the field.
+ *
+ * @param string $field_name
  */
-function _get_field_type($ss__field_name) {
-       return db_result(db_query("SELECT field_type FROM {contact_fields} 
-        WHERE field_name = '%s'", $ss__field_name));
+function _get_field_type($field_name) {
+  return db_query("SELECT field_type FROM {contact_fields} WHERE field_name = ':field_name'", array(':field_name' => $field_name))->fetchField();
 }

I started delving into the code but found so many issues with the Drupal 7 version that I'm considering writing my own version of this module. Do you have any specific timeframe for completing the Drupal 7 port?

beautifulmind’s picture

Thanks for your suggestion and consideration.
As you can see, the module is under development, and its not suggested to use the current devlopment release in 7.x branch. So, when there is a stable version in this branch, its likely that all the current issues would have been fixed.

Regards.

hershel’s picture

This line:

function contact_field_mail_alter($message) {

Should be:

function contact_field_mail_alter(&$message) {

HTH

beautifulmind’s picture

Please note that the portin is underway, and there are lots of issues. Pointing out one by one will only make this thread longer. You can post your issues once there is a stable release.

Regards.

summit’s picture

Title: Unable to use 7.x-dev » Still not able to use 7.x-dev, a year later

Hi,
Is this module maintained on D7?

I got still the same errors:

Notice: Undefined index: #title in _set_core_fields() (regel 361 van sites/all/modules/contact_field/contact_field_admin.inc).
Notice: Undefined index: #required in _set_core_fields() (regel 367 van sites/all/modules/contact_field/contact_field_admin.inc).
Notice: Undefined index: type in _get_fields() (regel 271 van sites/all/modules/contact_field/contact_field_admin.inc).
Notice: Undefined index: title in _get_fields() (regel 271 van sites/all/modules/contact_field/contact_field_admin.inc).
Notice: Undefined index: type in _get_fields() (regel 271 van sites/all/modules/contact_field/contact_field_admin.inc).
Notice: Undefined index: title in _get_fields() (regel 271 van sites/all/modules/contact_field/contact_field_admin.inc).
Notice: Undefined variable: form_id in _get_fields() (regel 304 van sites/all/modules/contact_field/contact_field_admin.inc).
Notice: Undefined index: #parents in form_builder() (regel 1770 van includes/form.inc).
Warning: implode() [function.implode]: Bad arguments. in form_builder() (regel 1770 van includes/form.inc).
Notice: Undefined index: #tree in form_builder() (regel 1800 van includes/form.inc).
Notice: Undefined index: #array_parents in form_builder() (regel 1823 van includes/form.inc).
Recoverable fatal error: Argument 1 passed to drupal_array_nested_key_exists() must be an array, null given, called in includes/form.inc on line 2041 and defined in drupal_array_nested_key_exists() (regel 6533 van includes/common.inc).

Is there may be an alternative for D7? How to proceed adding fields to side wide contactform on D7?

Thanks a lot in advance for your reply!
Greetings, Martijn

beautifulmind’s picture

Yes, the module is maintained and is under development. But the development process is slower than 6.x branch. I have been making lot of changes to this module. There will be a stable release soon.

I appreciate your co-opration and using the module.

Regards.

summit’s picture

Hi Beatifulmind, glad to hear!
Looking forward to stable release. So not investigating alternatives.
greetings,
Martijn

beautifulmind’s picture

Hello,
The stable release in 7.x branch will be published after Diwali.

Regards.

szt’s picture

Hi,
actually it's a very long Diwali... :)
I'd like to test the 7.1-1.0! ;)

tefnut’s picture

Hi, I really need this to, can you hurry up and fix it?

Many thanks X

Nick Robillard’s picture

I just upgraded my d6 site to d7 and sadly this is still not usable. :( I have not seen any progress lately so I will have to abandon this module and do this manually. Too bad.

drupalina’s picture

Seriously! When is this module going to be available in D7 in any working condition?

I've got a client who absolutely insists that that the contact form should have a simple "Your Telephone" text field. And there is no other way to add that field but use this module (which doesn't work at all.)

szt’s picture

Priority: Major » Critical

Since the module really unusable, bumping to critical...

kenorb’s picture

Category: Support request » Bug report
Issue summary: View changes
Status: Postponed » Active

The same problem here.

Enabled contact_listfield for the first time:

$ drush -y en contact_listfield
Exception 'DatabaseSchemaObjectExistsException' with message 'Table contact_fields already exists.' in includes/database/schema.inc:657
kenorb’s picture

Title: Still not able to use 7.x-dev, a year later » DatabaseSchemaObjectExistsException: Table contact_fields already exists.
kenorb’s picture

Status: Active » Needs review
StatusFileSize
new888 bytes
kenorb’s picture

StatusFileSize
new1.97 KB

And 2nd patch with proposed changes by jonathan_hunt in #3.

kenorb’s picture

Committed the proposed fixes and many other into my fork.
Please consider merging them.

kenorb’s picture

Priority: Critical » Major