내가 원하는 것은 다음과 같습니다.보기가있는 페이지에 양식을 렌더링하고 싶습니다. 이보기에는 '메모'(= CT 메모) 목록이 있습니다. 양식을 채울 때 메모가 저장되고 양식이 지워지고 새 메모가 목록에 추가됩니다. 페이지 새로 고침없이 모두.drupal 아약스 양식
난 모듈 new_note를 생성하고,이 기능 addes :
function new_note_form($nodeid = NULL) {
ctools_include('ajax');
// drupal_add_js(drupal_get_path('module', 'custom_forms') . '/js/note_form.js');
//dpm($nodeid);
module_load_include('inc', 'node', 'node.pages');
$form = node_add('note');
$form['field_note_reference']['und']['#value'] = '2';
$form['field_note_reference']['und']['#validated'] = 'TRUE';
$form['field_note_reference']['#attributes']['class'][] = "hidden";
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#executes_submit_callback' => FALSE,
'#ajax' => array(
'callback' => 'ajax_note',
'wrapper' => 'status',
),
);
$output= drupal_render($form);
dpm($form);
print $output;
}
function ajax_note(&$form, &$form_state) {
return 'test';
}
I 음표 목록 위에 렌더링되어 디스플레이 실내 블록 필드,이 기능을 사용한다. 여태까지는 그런대로 잘됐다.
유일한 문제는 양식을 제출할 때 ajax가 호출되지 않고 정상적인 제출이 완료된다는 것입니다.
아무도 도와 줄 수 있습니까?
@ 편집.
clive가 제안한 코드를 변경 한 후 코드를 변경하고 아약스를 작동 시켰습니다.
function new_notes_form($nodeid = NULL) {
global $user;
$node = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => 'note',
'language' => LANGUAGE_NONE,
);
$form_state = array();
$form_state['build_info']['args'] = array($node);
form_load_include($form_state, 'inc', 'node', 'node.pages');
$form = drupal_build_form('note_node_form', $form_state);
$form['field_note_reference']['und']['#value'] = '2';
$form['field_note_reference']['#attributes']['class'][] = "hidden";
$form['submit'] = array(
'#type' => 'button',
'#value' => 'Submit',
'#limit_validation_errors' => array(),
'#ajax' => array(
'callback' => 'ajax_note_replace',
'wrapper' => 'status',
),
);
return $form;
}
function ajax_note_replace(&$form, &$form_state) {
dpm("test");
dpm($form);
$output = '<h1>' . t('Hello World') . '</h1>';
// $node = node_load('6');
// $output .= drupal_render(node_view($node, $style = 'teaser', $options = array()));
ctools_include('ajax');
$commands = array();
$commands[] = ajax_command_prepend(".view-content", $output);
print ajax_render($commands); // this function exits.
exit;
}
@Clive, 나머지는 도와 줄 수 있습니까? 콜백에 노드를 저장하고 싶습니다 (유효한 경우?). ajax 콜백에서 node-id는 아직 저장되지 않았기 때문에 null입니까? 노드를 확인하고 저장할 수있는 방법, 그렇지 않은 경우 정상적인 양식 항목을 정상적으로 빨간색으로 설정하십시오.
'advanced_form_callback()'에 대한 코드를 게시 할 수 있습니까? – Clive
죄송합니다. 버전이 잘못되어 업데이트되었습니다. – Nealv