I have a custom module question.
I have a node form with a field (type textfield, unlimited values) that is called field_books. I have added 2 extra form elements via form alter, one textfield (lets call this custom_input) and one (ahah) button (custom_input_submit). When clicked on the custom_input_submit i want to use #ajax to fill the value of custom_input in a new item of my field_books field. So field_books should be incremented by one and have the submitted value of custom_input.
... form alter :
$form['custom_input'] = array(
'#type' => 'textfield',
'#title' => ('new book'),
);
$form['custom_input_submit'] = array(
'#type' => 'submit',
'#value' => t('Add to book'),
'#ajax' => array(
'callback' => 'ccc_selected_books',
'wrapper' => 'search-selected-books-wrapper',
'method' => 'replace'
),
'#submit' => array('ccc_add_books'),
'#limit_validation_errors' => array(), //don't validate other element of the form
);
/**
* Ajax callback that returns the form books element
*/
function ccc_selected_books($form, $form_state) {
return $form['field_books'];
}
<?php
/**
* Form submit callback (ajax) that moves a book from custom input to field_books
*/
function ccc_add_books($form, &$form_state) {