I want a button that runs a callback function using the AJAX method included in Form API. The button I have still submits the whole node edit form. I don't want it to do that - just pass a couple variables to the callback function and display the results. How can I do that?
This is my FAPI code for that button:
$form['rid_import']['rid_get'] = array(
'#type' => 'button',
'#value' => t('Import'),
'#attributes' => array(
'id' => array('fetch_rid'),
'class' => array('col-sm-3', 'col-xs-4')
),
'#parents' => array('rid_import'),
'#limit_validation_errors' => array(),
'#executes_submit_callback' => false,
"#submit" => array('sql_no_submit'),
'#ajax' => array(
"callback" => 'sql_fetch_restid',
"wrapper" => 'rid_sql_query',
"event" => 'click'
)
);
EDIT
You're right, I was being unclear. Basically what I wanted is something that works like your "Add More" or "Remove" buttons when you have multiple-value fields, but just to run my function without reloading the page – grab some data from the DB and show it there on the node edit form. I have a multivalue field collection that should be populated with those values and then saved together with the rest of the node. That's why I don't want it to go ahead and save the node. However, if it isn't possible I guess I will have to find another way to do what I need.
And tried to add a submit function, still reloads the whole page.