I'm using a custom content type with additional CCK based fields. I'm using a 'Create New Game' link on my page that will use AJAX to pull the content form and display it on the page. I have this need as my CCK fields will display select lists determined by the page that calls the form via AJAX. (Page X needs select options 1-4 and Page Y needs select options 5-8).

My problem with that when calling drupal_get_form( "MY_CUSTOM_FORM_FUNCTION" ) it only returns the fields I have in my custom content type. It does not include the CCK fields I've added to my content type.

Does anyone know how I can go about having it load all the CCK fields without actually calling the page 'node/type/add'

Comments

danielb’s picture

well I have no idea what "MY_CUSTOM_FORM_FUNCTION" means, you could probably get much better help if you used real code samples.

to put a page form:


print node_add('page');

etc..

melban’s picture

Regular node/game/add form displays CCK fields
http://www.smwebdesigns.com/lj/maven.drupal_get_form.png

Trying to pull the form using AJAX only displays hook_form() fields.
http://www.smwebdesigns.com/lj/maven.ajax.drupal_get_form.png

function maven_game_menu() {
  $items['ajax/league_add_game'] = array(
    'title' => 'League',
    'page callback' => 'maven_game_ajax_add',
    'access arguments' => array('game create'),
  );
  return $items;
}

function maven_game_ajax_add()
{
	if (!empty($_POST['js']))
	{
		$html = drupal_get_form( 'maven_game_form' );
		drupal_json(array(
			'html' =>  $html
			)
		);
		exit;
	}
	return t( 'invalid request');
}


function maven_game_form(&$node)
{
  global $nid;
  $iid = isset($_GET['iid']) ? (int)$_GET['iid'] : 0;
  $type = node_get_types('type', $node);

  if (empty($node->body)) {
    // If the user clicked a "blog it" link, we load the data from the
    // database and quote it in the blog.
    if ($nid && $game = node_load($nid)) {
      $node->body = '<em>'. $game->body .'</em> ['. l($game->name, "node/$nid") .']';
    }

    if ($iid && $item = db_fetch_object(db_query('SELECT i.*, f.title as ftitle, f.link as flink FROM {aggregator_item} i, {aggregator_feed} f WHERE i.iid = %d AND i.fid = f.fid', $iid))) {
      $node->title = $item->title;
      // Note: $item->description has been validated on aggregation.
      $node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n";
    }

  }

  $form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => !empty($node->title) ? $node->title : 'game name', '#weight' => -5);
  return $form;
}

nevets’s picture

You need to use the form for adding/editing a node, your form represents just part of the question.

There is an alternative to using AJAX.

Lets say your content type is 'maven_game', the default path for adding content of this type would be node/add/maven_game, but something like node/add/maven_game/123 also works. The 123 is ignored by default but your code can use arg(3) to retrieve it (node would be arg(0), etc).

melban’s picture

my whole issue was wanting to control what select values showed on a CCK field by passing something from the form page to that PHP Code field was my overall objective.

Thanks for the solution.