Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal 7 file upload (without hook_form)
    primarykey
    data
    text
    <p>Here is a conundrum that's had me stumped for the past few days. I am using a modal form in Drupal 7, so working outside of the hook_form system, trying to upload an image. The form is submitted through an ajax post, which prevents me from submitting the file along with the post. what I've done is in the ajax callback, create a new form element with the file input and then trigger a submit, posting to my module-defined page. </p> <p>Original input element:</p> <pre><code>&lt;input type="file" id="chooseImage" name"someImage" class="form-file"&gt; </code></pre> <p>js triggering submit:</p> <pre><code>$.ajax({ type:'POST', url:$('#originalForm').attr('action'), data: data, success: function(response) { if (response.success) { $('&lt;form id="imageForm" method="POST" action="upload/image/'+response.data.nid+'"&gt;&lt;/form&gt;').appendTo($('#imageSubmit')); $('#chooseImage').appendTo($('#imageForm')); console.log($('#imageForm')); $('#imageForm').submit(function(e){ console.log(e); alert('freeze! hammertime...'); }); //This should post the file but it isn't... $('#imageForm').trigger('submit'); } }, dataType:'json' }); </code></pre> <p>The submit event shows the file properties just fine. However, on the backend, where my page callbacks end...</p> <pre><code> function myModule_image_upload($param){ error_log('number of files = '.sizeof($_FILES)); } </code></pre> <p>I am showing no files posted. I am guessing that the browser is removing the file data in the post after .submit() runs and if that is the case, I'm probably powerless to do anything about it, so I'll have to implement a separate menu within the hook system for image uploads.</p> <p>Also, whatever it is that this is really doing, it seems to permanently break watchdog, forcing me to re-import a fresh dump.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload