0

I have one dynamic form, the form field will depend on the url. For example, there will be only one field when the url dose not have second parameter. And there will have one more field when there is parameter.

It works fine without ajax. When i use ajax to replace the form, it always only outputs the first field. When i use dsm($entry) after ajax callback, it is empty. before ajax callback, there is content in it.

function quotes_form($form, &$form_state,$token){
$entry=arg(1);

$form['arrival_city_1'] = array(
    '#default_value'=>$arrival_city_1,
    '#type' => 'select',
    '#required' => TRUE,
    '#options'=>$arrival_array,

);
if(isset($entry)){

    $form['arrival_city_2'] = array(
    '#default_value' => $arrival_city_2,
    '#type' => 'select',
    '#options'=>$return_arrival_array,
          );

}

    $form['stop'] = array(
    '#type' => 'select',
    '#options' =>$stop_array,
    '#default_value' => $stop,
    '#ajax' => array(
        'callback' => 'ajax_example_autocheckboxes_callback',
        'method' => 'replace',
        'effect' => 'fade',
    ),

);

 }

function ajax_example_autocheckboxes_callback($form, $form_state){

   $form_outputs=render(drupal_get_form('quotes_form',$token));
   return array(
        '#type' => 'ajax',
        '#commands' => array(
            ajax_command_replace("#checkboxes-div", $form_outputs)
                )
            );
}

How can i make it execute the if(isset($entry)) part?

user3210341
  • 77
  • 1
  • 2
  • 14

1 Answers1

0

arg(1) will be true if you use a path of two parts .. so if the current url is abc just goto abc/xyz

but I wonder about the rest of your code .. like the replace command, it is replacing some element with id checkboxes-div, but I don't see you defining any elements with this id