MyBB Community Forums

Full Version: Admin form submit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys I have a problem submitting a form with jquery in admin page

jquery
<script type="text/javascript">
$(document).ready(function() {
 $("input[name='continue']").click(function(event) {
 event.preventDefault();
 var formData = {
 'my_post_key' : $('input[name="my_post_key"]').val(),
 'file_content' : $("#file_content").val()
 }

 $.ajax({
 url: "./index.php?module=file&action=edit&directory=dir_with_php&file=file_with_php,
 type: "post",
 dataType: "json",
 data: formData,
 success: function(data) {
 console.log(data);
 $("div#inner").prepend("<div id=\"flash_message\" class=\""+data.type+"\">"+data.msg+"</div>");
 },
 error: function(data){
 console.log(data);
 $("div#inner").prepend('<div id="flash_message" class="error">Errore durante il salvataggio. Si prega di riprovare. <pre id="response"></pre></div>');
 $("pre#response").text(data.responseText);
 }
     });
 });
});
</script>

PHP page

$form = new Form("index.php?module=file&amp;action=edit&amp;directory=$dir&amp;file=$file", "post", "edit_file");
            
            $form_container = new FormContainer("Modifica file: ".$dir."/".$file, 'tfixed');
            
            $form_container->output_row("", "", $form->generate_text_area('file_content', $content, array('id' => 'file_content', 'class' => '', 'style' => 'width: 100%; height: 500px;')));
        $form_container->end();
            
            $buttons[] = '<input class="submit_button" type="button" name="continue" value="Salva e continua">';
            $buttons[] = $form->generate_submit_button("Salva e chiudi", array('name' => 'save'));
            $buttons[] = $form->generate_submit_button("Chiudi", array('name' => 'close'));
            
            $form->output_submit_wrapper($buttons);
            
            $form->end();

In pre tag it show me all the code of the currently page

I solved it by creating a new page for quick save.