I am trying to modify the fields created in a webform to reach something like this:

$form['province']= array (
'idProvincia' => array (
'#type' => 'select',
'#title'=> t('Province'),
'#description' => '',
'#weight' => '6',
'#options' => custom_forms_obtenerProvincias(),
'#suffix' => '

',
'#ahah' => array(
'path' => 'custom_forms/carga_localidades/callback',
'wrapper' => 'poblacionesActBlock',
'effect' => 'fade'
),
),
);

$form['poblaciones'] = array(
'#tree' => TRUE,
'#prefix' => '

',
'#suffix' => '

'
);

$form['poblaciones']['idLocalidad'] = array(
'#type' => 'select',
'#title' => t('Town'),
'#options' => custom_forms_obtenerLocalidades(),
);

i am trying it through the hook custom_forms_form_alter(&$form, &$form_state, $form_id)
that I´m using in my module custom_forms but i don´t find the correct way to make this.
I´m not able to add what i want to the fields created

Can anybody helpme? thanks in advance!!!

Comments

Enxebre’s picture

Explained in a better way, what i need to have are two select fields ( created in the webform ) relationed by an onchange event

quicksketch’s picture

Enxebre’s picture

Thank you for your reply.
I read this link and I´m using the conditional_webform module for load somefields in my webform but it isn´t exactly what I want in this case.
I want to load always the same field bringing differents values depending on the value selected in the other field.

Modifing in the selec.inc of webform module like this:

function _webform_render_select($component, $value = NULL, $filter = TRUE) {
if ($component["form_key"] == province){
   $element= array (

            '#type' => 'select',
			'#title'=> t('Province'),
		    '#required' => $component['mandatory'],
            '#description' => '',
			'#weight' => '6',
            '#options' => custom_forms_obtenerProvincias(),
    		'#suffix' => '<div> <noscript>
							<div><input class="marginTopRight_5  botonRecargar floatRight" name="recargar" onclick="" type="submit" value="" /></div>
						  </noscript> </div>',
            '#ahah' => array(
                'path' => 'custom_forms/carga_localidades/callback',
                'wrapper' => 'poblacionesActBlock',
                'effect' => 'fade'
            ),
        
    ); 

}else{
  $element = array(
    '#title' => $filter ? _webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#required' => $component['mandatory'],
    '#weight' => $component['weight'],
    '#description' => $filter ? _webform_filter_descriptions($component['extra']['description']) : $component['extra']['description'],
    '#theme_wrappers' => array('webform_element_wrapper'),
    '#pre_render' => array('webform_element_title_display'),
    '#post_render' => array('webform_element_wrapper'),
    '#webform_component' => $component,
  );
}

I have some positives results but when i´m not able to catch the data sent by this field.

function custom_forms_cambiarPoblaciones_callback() {

   $salida = array(
        '#type' => 'select',
        '#title' => t('Town'),
        '#options' => custom_forms_obtenerLocalidades($_POST['province']),
        '#default_value' => $_POST['idLocalidad'],
        '#name' => 'idLocalidad',
        '#id' => 'edit-poblaciones-idLocalidad',
    );

$_POST['province'] Seems not to be the correct name. How can I see all the $_POST variables in that moment?

I tried adding something like this in the function custom_forms_cambiarPoblaciones_callback() :

foreach($_POST as $nombre_campo => $valor){
$valores[$i] = $valor;
$i++;
} 
var_dump($valores);
    $salida = drupal_render($salida);
    print drupal_json(array('status' => TRUE, 'data' => $salida));
	
    exit();
}

but I get a callback error.

Thank you!!