I'm playing around with the CCK for the first time, and I am getting some weird behavior when I try to create content from a CCK content type. All fields that are defined as freeform text fields are not being correctly saved to the database; only the first character is being saved. Thus if I enter "abc" into the text field, only the value "a" is saved in the table. If I click the Preview button, the values are displayed properly, but when I click Submit, they disappear entirely (not even the first character is displayed, even if it exists in the DB!). If I go to edit the page, the text fields are empty; again, not even the first character is displayed, although it exists in the DB. Drop-down lists and web URLs are saved with no problem.

I downloaded the latest CVS of the CCK and installed on 4.7RC2.

Anybody have any ideas?? I'm tearing my hair out here!

Thanks so much!

Comments

JonBob’s picture

I need a little more information for diagnosis, if you can provide it:

- The version number of content.module (in the $Id line at the top of the file)
- The version number of text.module
- Is the field set to accept multiple values?
- Is it set as plain text or filtered text?
- Is it a single-line text field, or multiple-line text area?

jdw23’s picture

Wow, thanks for the quick follow-up!

Version of content.module: $Id: content.module,v 1.49 2006/04/18 21:01:10 JonBob Exp $
Version of text.module: $Id: text.module,v 1.29 2006/04/17 19:25:41 JonBob Exp $

Multiple values: NO
Plain text: YES
Single line: YES

JonBob’s picture

I can't immediately reproduce this with these settings. I'm using the latest CVS copy of Drupal, so it is conceivable this could be a core-related issue that has been fixed since the release of RC2. I'm not aware of any changed that are relevant, though.

The symptoms sound like the data is being passed back as $node->field_whatever rather than $node->field_whatever[0], for anyone else looking into the code on this one.

dado’s picture

i am seeing this also (only 1st character is getting added to text fields, but web url field populates properly). But i only get this problem only when i create a node using (cvs version of) node_import. i am looking into it.

Using latest CCK, Drupal from CVS (as of 4/23).

dado’s picture

Exactly as JonBob said, the issue for me was that I had node_import populating the node field as
$node->field_whatever rather than $node->field_whatever[0]

I had coded it this way previously but it appears that CCK text field changed recently. I do not see that my issue implies there is any current bug in CCK.

JonBob’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)
tspratt’s picture

I am seeing this issue, but am not using CCK, just the Drupal Administration Content Types screens to create the field.

I defined the field as a multiple value, text field.

I am using actionscript to update the content. for example:
nodeTemp.field_images = new Array("abc.gif","test","test2");

I also tried:
nodeTemp.field_images.push(("abc.gif");
nodeTemp.field_images.push("test");
nodeTemp.field_images.push("test2");
with the same results,
specifically "a", "t", "t"

I see that this is closed and all and am not really expecting a response, but the problem is exactly what I am experiencing, so I decided to post here.

I will probably use one of the unused built-in fields to hold my data but would appreciate any other suggestions.
Tracy

mErilainen’s picture

Version: 6.x-1.x-dev » 6.x-2.4

I'm trying to save a value to node edit form, and I get exactly same behavior.

<?php
function alterforms_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
  case 'experience_node_form':
    $form['field_ip_address'][0]['#value'] = $_SERVER['REMOTE_ADDR'];
  break;
}
?>

field_ip_address is a CCK textfield. When I go to create a new "Experience", I can see only first number of my IP.
Any idea what I might be doing wrong? I can change other values like button names etc. this way without problems.

mErilainen’s picture

Status: Closed (fixed) » Active

Opening issue.

yched’s picture

Version: 6.x-2.4 » 4.7.x-1.x-dev
Status: Active » Closed (fixed)

Sorry, reopening issues closed 3 years ago is not the way to go and will only add confusion since issues are most definitely unrelated.

As a quick tip, I'd say your code needs to be changed to
$form['field_ip_address'][0]['value']['#value'] = ...

But other than that, please open a separate support request.

markus_petrux’s picture

Version: 4.7.x-1.x-dev » 6.x-2.4

Closing back the issue. This is a pretty old thread that has been re-open for completely unrelated issues. CCK has changed a little since then.

@tspratt #8: Yours seem to be a problem not related to CCK.

@mErilainen #9: before altering a field in hook_form_alter(), use var_dump() or similar to figure out the structure of the array.

markus_petrux’s picture

Version: 6.x-2.4 » 4.7.x-1.x-dev

Oops! We have replied at the same time.

mErilainen’s picture

I was playing around with this myself and found out that using
$form['field_ip_address'][0]['#default_value']['value'] = $_SERVER['REMOTE_ADDR'];
did the trick.

bigplanet’s picture

Version: 4.7.x-1.x-dev » 6.x-2.0

I am having a similar issue when trying to hook a CCK field, but I can't see how to combine mErilainen's solution and still make the field hidden. Again, the symptoms are that only the first character of value is being inserted.

 $account = arg(1);
        $result = db_query("SELECT account FROM node, users WHERE node.nid = users.account AND users.uid = $account");
        $club = db_result($result);
        $form['field_sr_account'] = array( '#type' => 'hidden', '#value' => $club);

I am able to view the correct value in the HTML source and with drupal_set_message after the insert, yet the value inserted is only the first character.

KarenS’s picture

Version: 6.x-2.0 » 4.7.x-1.x-dev

This is a closed, three year old issue for a very very old, totally outdated, version of CCK. Don't reopen it to discuss something going on in the current code and don't change the version number.