Remove form elements with ajax I have made a form with form loop as I am setting the $form_state['number'] for the fields count.

I want to remove a full row after clicking on remove button in front of row by taking row_id. So I want to ask is there any way to pass id of row in submit function of remove button or check which button pressed and fetching id of that button in submit function.

 for ($i = 1; $i &lt;= $form_state['number']; $i++) {
    $form['myform'][$i]['email'] = array(
        '#type' =&gt; 'textfield',
        '#size' =&gt; 18,
        '#autocomplete_path' =&gt; 'mypath',
        '#prefix' =&gt; '&lt;div id="feedbackrow_'.$i.'"&gt;',
    );
    $form['myform'][$i]['roles'] = array(
        '#type' =&gt; 'select',    
        '#options' =&gt; array('' =&gt; '', 'master' =&gt; 'master', 'student' =&gt; 'student'),
    );
     $form['oldfeedbackmarkup'][$i]['remove'] = array(
       '#type' =&gt; 'submit',
       '#value' =&gt; t('Remove'),
       '#submit' =&gt; array('mysubmit_button'),
       '#ajax' =&gt; array(
              'wrapper' =&gt; 'myform_wrapper',
              'callback' =&gt; 'submit_by_ajax',   
        ),
        '#prefix' =&gt; '&lt;div class="form-item"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;&lt;/div&gt;',
    );
}
It's actually easier than you think :)

You can access a $form_state['triggering_element'] in your ajax callback function.

Something like this:


function my_ajax_callback($form, $form_state) {
  $ps = &$form_state['triggering_element']['#parents'];
  $k = $ps[2]; // field collection row number 
  $collection = $form[$ps[0]][$ps[1]][$ps[2]];
  $element = $ps[3];
  ...


that was the snippet to access a changed textfield inside a field collection with multiple rows. Just adopt it for your particular form structure.