[development] Values not retained

pavithra m pavspavi88 at gmail.com
Mon Jan 10 06:44:59 UTC 2011


This part of the code is not retaining the previous value.....


$form['characteristics']=array(
'#type' => 'textfield',
'#size'=> 20,
//'#title' => t('rows @n', array('@n' => ($delta + 1))),
'#prefix'=>'<table class="table2"><tr><td class="table2row">',
'#suffix'=>'</td>',
'#default_value' => !empty($form_state['values']['characteristics']) ?
$form_state['values']['characteristics'] : '',
'#parents' => array('rows', $delta, 'chars'),
);

$form['description']=array(
'#type' => 'textfield',
'#size'=> 20,
//'#title' => t('rows @n', array('@n' => ($delta + 1))),
'#prefix'=>'<td class="table2row">',
'#suffix'=>'</td>',
'#default_value' => !empty($form_state['values']['description']) ?
$form_state['values']['description'] : '',
'#parents' => array('rows', $delta, 'descr'),
);
$form['minimum']=array(
'#type' => 'textfield',
'#size'=> 20,
// '#title' => t('rows @n', array('@n' => ($delta + 1))),
'#prefix'=>'<td class="table2row">',
'#suffix'=>'</td>',
'#default_value' => !empty($form_state['values']['minimum']) ?
$form_state['values']['minimum'] : '',
'#parents' => array('rows', $delta, 'min'),
);
$form['maximum']=array(
'#type' => 'textfield',
'#size'=> 20,
//'#title' => t('rows @n', array('@n' => ($delta + 1))),
'#prefix'=>'<td class="table2row">',
'#suffix'=>'</td></tr></table>',
'#default_value' => !empty($form_state['values']['maximum']) ?
$form_state['values']['maximum'] : '',
'#parents' => array('rows', $delta, 'max'),
);
-- 
*Cheers*
*
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20110110/585493b3/attachment-0001.html 
-------------- next part --------------
<?php
// $Id$


/**
 * @file
 * 
 * The pavi module.
 */

/**
 * Implements hook_help().
 */
function pavi_help($path, $arg) {
  $output = '';
  switch ($path) {
    case "admin/help#pavi":
      $output = '<p>' . t("Displays the products") . '</p>';
      break;
  }
  return $output;
}

/**
 * Implements hook_perm().
 */
 
 

/*
function pavi_perm() {
  return array(
    'access pavi',
    'edit pavi',
    'administer pavi',
    'add to pavi',
  );
}

*/



	
function pavi_menu(){
$items = array();
$items['pavi'] = array(
		'title' => t('PRODUCTS'),
		'page callback' => 'drupal_get_form',
		'page arguments'=>array('pavi_form'),
		'access arguments' => array('access pavi'),
		'type' => MENU_NORMAL_ITEM,
	);

$items['pavi/js']=array(
	'title' => 'Javascript Choice Form',
	'page callback' => 'drupal_get_form',
	'page  arguments'=>array('pavi_rows_js'),
	 'access arguments' => array('access pavi'),
	'type'=> MENU_CALLBACK,
);




return $items;
	}
	






function pavi_form(&$form_state)
{


$form['enteredfrom']=array(
	'#type'=>'textfield',
	'#title'=>'',
	 '#default_value' => !empty($form_state['values']['enteredfrom']) ? $form_state['values']['enteredfrom'] : '',
	'#prefix'=>'<tr><td class="labeltext">ENTERED FROM</td><td class="textbox">',
    '#suffix'=>'</td></tr></table>',
		
);



// chars headr
    
	

if (isset($form_state['rows_count'])) {
    $rows_count = $form_state['rows_count'];
  }
  else {
    $rows_count = 1;
  }

$form['rows_wrapper'] = array(
    '#title' => t("Characteristics"),
    '#prefix' => '<div id="rows-wrapper">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
    '#tree'=> FALSE,
  );
  
  $form ['rows_wrapper']['characteristicshead']=array(
			'#type'=>'hidden',
			'#title'=>'',
			'#prefix'=>'<table class="table2"><tr><th class="table2head">CHARACTERISTICS',
			'#suffix'=>'</th>',
		
		);
	$form['rows_wrapper']['descriptionhead']=array(
			'#type'=>'hidden',
			'#title'=>'',
			'#prefix'=>'<th class="table2head">DESCRIPTION',
			'#suffix'=>'</th>',
		);
	$form['rows_wrapper']['minimumhead']=array(
			'#type'=>'hidden',
			'#title'=>'',
			'#prefix'=>'<th class="table2head">MINIMUM</th>',
			'#suffix'=>'</th>',
		);
	$form['rows_wrapper']['maximumhead']=array(
			'#type'=>'hidden',
			'#title'=>'',
			'#prefix'=>'<th class="table2head">MAXIMUM',
			'#suffix'=>'</th></tr></table>',
		);


$form['rows_wrapper']['rows']=array(
	'#prefix' => '<div id="rows-choices"><table class="table2">',
    '#suffix' => '</table></div>',

  );

  
 for ($delta = 0; $delta <$rows_count; $delta++) {
 
		$chars= $form_state['values']['rows_wrapper']['rows'][$delta]['characteristics'] ;
		$descr= $form_state['values']['rows_wrapper']['rows'][$delta]['description'];
		$min=$form_state['values']['rows_wrapper']['rows'][$delta]['minimum'] ;
		$max=$form_state['values']['rows_wrapper']['rows'][$delta]['maximum'];
 
    $form['rows_wrapper']['rows'][$delta]= _table_rows_form($delta,$chars,$descr,$min,$max,&$form_state);
	
}


$form['rows_wrapper']['pavi_add_more']= array(
	'#type' => 'submit',
    '#value' => t('More Rows'),
    '#description' => t(" click here to add more characteristics."),
    '#weight' => 1,
	
    '#submit' => array('pavi_add_more_rows_submit'), // If no javascript action.
    '#ahah' => array(
      'path' => 'pavi/js',
      'wrapper' => 'rows-choices',
      
      'effect' => 'fade',
    ),
  );
  
  
   $form['submit'] = array(
  '#type' => 'submit',
  
  '#value' => t('ADD TO TABLE')
 
 );
 
 
 return $form;
 
 }
 
 
 function pavi_add_more_rows_submit($form, &$form_state) {
 
	//node_form_submit_build_node($form, $form_state);
  
	if ($form_state['values']['pavi_add_more']) {
			$n = $_GET['q'] == 'pavi/js' ? 1 : 5;
			$form_state['rows_count'] = count($form_state['values']['rows']) + $n;
	}
  
  }
  
 
 
 
 function _table_rows_form($delta,$chars,$descr,$min,$max,&$form_state) {
 
	$form=array(
		'#tree'=>TRUE,
		);
	
	//rows
	
	$form['characteristics']=array(
			'#type' => 'textfield',
			'#size'=> 20,
		//'#title' => t('rows @n', array('@n' => ($delta + 1))),
			'#prefix'=>'<table class="table2"><tr><td class="table2row">',
			'#suffix'=>'</td>',
		'#default_value' => !empty($form_state['values']['characteristics']) ? $form_state['values']['characteristics'] : '',
			'#parents' => array('rows', $delta, 'chars'),
		);

	$form['description']=array(
			'#type' => 'textfield',
			'#size'=> 20,
		//'#title' => t('rows @n', array('@n' => ($delta + 1))),
			'#prefix'=>'<td class="table2row">',
			'#suffix'=>'</td>',
			'#default_value' => !empty($form_state['values']['description']) ? $form_state['values']['description'] : '',
			'#parents' => array('rows', $delta, 'descr'),
		);
	$form['minimum']=array(
			'#type' => 'textfield',
			'#size'=> 20,
		//	'#title' => t('rows @n', array('@n' => ($delta + 1))),
			'#prefix'=>'<td class="table2row">',
			'#suffix'=>'</td>',
			'#default_value' => !empty($form_state['values']['minimum']) ? $form_state['values']['minimum'] : '',
			'#parents' => array('rows', $delta, 'min'),
		);
	$form['maximum']=array(
			'#type' => 'textfield',
			'#size'=> 20,
			//'#title' => t('rows @n', array('@n' => ($delta + 1))),
			'#prefix'=>'<td class="table2row">',
			'#suffix'=>'</td></tr></table>',
			'#default_value' => !empty($form_state['values']['maximum']) ? $form_state['values']['maximum'] : '',
			'#parents' => array('rows', $delta, 'max'),
		); 
 return $form;
    
 
}

function pavi_rows_js() {
		
		include_once 'modules/node/node.pages.inc';
		$form_state = array('storage' => NULL, 'submitted' => FALSE);
		$form_build_id = $_POST['form_build_id'];
		
	
		$form = form_get_cache($form_build_id, $form_state);
		$args = $form['#parameters'];
		$form_id = array_shift($args);
		
		
		$form['#redirect'] = FALSE;
		
		
		$form['#post'] = $_POST;
		$form['#programmed'] = FALSE;
		$form_state['post'] = $_POST;
		
		
		drupal_process_form($form_id, $form, $form_state);
		
		
		
		$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
		
		
		$rows_form = $form['rows_wrapper']['rows'];
		unset($rows_form['#prefix'], $rows_form['#suffix']); // Prevent duplicate wrappers.
		$output = drupal_render($rows_form);

 print drupal_json(array('status' => TRUE, 'data' => $output));
}



More information about the development mailing list