I have a node form with some fields, now I want to append some more fields to it on an ajax callback. in the ajax page I have rendered the new form elements with drupal_render function
My problem is that I am not getting the newly built form fields in POST or form_state. Shall I use AHAH or can I continue with this ajax calls?

$form['country'] = array( 
            '#title'    =>t('Ship To'), 
            '#required' => true ,
            '#options' => $options,
            '#weight' =>10,
            '#attributes' =>  array('id' => $cn_var),
        $form['dyn_cost'] = array( 
            '#title'    =>t('Shipping Cost'),   
            '#required' => true ,
            '#size' =>25,
            '#weight' =>11,
            '#id' =>  $co_var,

        print drupal_render($form);

This is my ajax form and it is supposed to be appending to the node form.

  • 1
    May be you want to check the AJAX examples in the example module.
    – BetaRide
    Commented Mar 28, 2012 at 6:13
  • Is there any problem with my current code ?
    – niksmac
    Commented Mar 28, 2012 at 6:15
  • 5
    Use AHAH. By printing and exiting you're not altering the $form that Drupal knows, and it won't accept data that it's not expecting. In D6 it's not as fun as #ajax in D7, though. Check out an answer I just gave that's very similar, although its syntax applies to D7: drupal.stackexchange.com/questions/59224/… Commented Jan 31, 2013 at 20:34
  • @CharlieS why not to post it as an answer? NikhilM are you still interested in this at all?
    – Mołot
    Commented Dec 30, 2013 at 15:27

1 Answer 1


You can use Conditional Fields module to display form fields with certain conditions. No need to use custom ajax calls.

Conditional Fields allows you to manage sets of dependencies between fields. When a field is “dependent”, it will only be available for editing and displayed if the state of the “dependee” field matches the right condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.