I'm currently working on a website which mail user attachments to the owner of the website. However I used a form to submit image files to mail PHP file and then it send the email. It worked perfectly until I override form submit function with Javascript and use ajax to submit it and get the output from mail PHP file to add some additional functionalities.   &lt;form id="contactForm" action="php/sendcontactusmail.php" method="post" enctype="multipart/form-data"&gt;     &lt;div class="row"&gt;         &lt;div class="col-md-6"&gt;         &lt;!-- Additional Codes for email input and subject inputs --&gt;             &lt;div class="form-group"&gt;                 &lt;label for="subject" id="uploadImageLabelId"&gt;Upload Pictures of the Job&lt;/label&gt;                 &lt;form  enctype="multipart/form-data" &gt;                     &lt;input type="file" name="fileToUpload" id="imageUploadInputId" accept="image/*" id="fileToUpload" multiple&gt;                 &lt;/form&gt;             &lt;/div&gt;             &lt;!-- Additional Codes for Message inputs and others --&gt;             &lt;div class="col-md-12"&gt;                 &lt;button type="submit"class="btn btn-primary pull-right" id="btnContactUs"&gt;Send Message&lt;/button&gt;             &lt;/div&gt;       &lt;/div&gt;    &lt;/div&gt; &lt;/form&gt;   Javascript code:  $("#contactForm").submit(function(){     $.ajax({         type:"POST",         url : "php/sendcontactusmail.php",         dataType:"json",         data: $("#contactForm").serialize(),         success: function (data)         {             alert(data);             }      });     return false; });        **My Problem **  PHP code:  if(filter_var($_POST["subject"], FILTER_SANITIZE_STRING)=="estimate") {     if($_POST &amp;&amp; isset($_FILES['fileToUpload']))     {                // Some Codes to send email     }     else          echo json_encode(isset($_FILES['fileToUpload'])); } else {     // Some codes for send separate email. }    when I run my program, alert box shows false. Which clearly means that  isset($_FILES['fileToUpload']) function returns false. I tried every way to fix that. But couldn't find the problem. Any guesses?   Note   When I run the website on my local server I selected a compatible jpg file. But it says file is not set.      Update  I went through lots of stackoverflow questions and none of their solutions gave me a true return statement. Hope this wouldn't be a duplicated question.
7478
I would like to upload a file asynchronously with jQuery.     $(document).ready(function () {     $("#uploadbutton").click(function () {         var filename = $("#file").val();          $.ajax({             type: "POST",             url: "addFile.do",             enctype: 'multipart/form-data',             data: {                 file: filename             },             success: function () {                 alert("Data Uploaded: ");             }         });     }); }); &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt;&lt;/script&gt; &lt;span&gt;File&lt;/span&gt; &lt;input type="file" id="file" name="file" size="10"/&gt; &lt;input id="uploadbutton" type="button" value="Upload"/&gt;     Instead of the file being uploaded, I am only getting the filename. What can I do to fix this problem?
105831
Drupal 7. Custom module. I have a content type 'RFI' with a handful of fields I created with Drupal UI. I want a user to: fill out a form &amp; click submit while drupal: saves fields to database, creates a new node of 'RFI' and populates the fields of the node with the content provided by the form's corresponding fields.  From what I understand:  Build a form with fields (taking from the 'DBTNG examples' module just for clarity):  function rfi_build_form($form, &amp;$form_state) { $form = array();  $form['add'] = array( '#type'  =&gt; 'fieldset', '#title' =&gt; t('Add a person entry'), ); $form['add']['name'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Name'), '#size'  =&gt; 15, ); $form['add']['surname'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Surname'), '#size'  =&gt; 15, ); $form['add']['age'] = array( '#type'  =&gt; 'textfield', '#title' =&gt; t('Age'), '#size'  =&gt; 5, '#description' =&gt; t("Values greater than 127 will cause an exception. Try it - it's a    great example why exception handling is needed with DTBNG."), ); $form['add']['submit'] = array( '#type'  =&gt; 'submit', '#value' =&gt; t('Add'), ); return $form; }   Here the form fields are saved to database with database API.  function rfi_build_submit($form, &amp;$form_state) { global $user;  // Save the submitted entry. $entry = array( 'name'    =&gt; $form_state['values']['name'], 'surname' =&gt; $form_state['values']['surname'], 'age'     =&gt; $form_state['values']['age'], 'uid'     =&gt; $user-&gt;uid, ); $return = dbtng_example_entry_insert($entry); if ($return) { drupal_set_message(t("Created entry @entry", array('@entry' =&gt; print_r($entry, TRUE)))); } }   Now here is how I know how to create a node of RFI type. How do I take the values of the fields above [name], [surname], [age] and have them related to corresponding fields in my content type?  function rfi_build_type($form, &amp;$form_state){ $node = new stdClass(); $node-&gt;type = 'rfi'; $node-&gt;name = ''; $node-&gt;surname = ''; $node-&gt;age = ''; $node-&gt;language = 'en'; $node-&gt;uid = 1; node_save($node); }   I was thinking that since the fields have been saved already, that I could use a database query to get these values, but intuition tells me I'm overlooking something.  Thank you!
44846
I used the jQuery Form plugin for asynchronous form submission. For forms that contain files, it copies the form to a hidden iframe, submits it, and copies back the iframe's contents. The problem is that I can't figure out how to find what HTTP status code was returned by the server. For example, if the server returns 404, the data from the iframe will be copied as normal and treated as a regular response.  I've tried poking around in the iframe objects looking for some sort of status_code attribute, but haven't been able to find anything like that.    The $.ajax() function can't be used, because it does not support uploading files. The only way to asynchronously upload files that I know of is using the hidden iframe method.
114215
I have my style.php file looking like this.  &lt;?php  header('Content-Type: text/css');?&gt; #div{     background:&lt;?php  echo get_option('bgcolor');?&gt;; }   This does not work, but when I do this it works.  &lt;?php  header('Content-Type: text/css');?&gt; #div{     background: &lt;?php  echo 'blue';?&gt;; }   What would be the problem?  This is the mainfile.php   &lt;?php       function test(){     global get_option('bgcolor');?&gt;          &lt;input type="text" id="bgcolor" name="post_popup_settings[bgcolor]" value="&lt;?php echo get_option('bgcolor');?&gt; " /&gt;     &lt;?php }     add_action('admin_head','test');   This is actually in the admin section.
61666
In reading I am not sure if the issue below could have something to do with needing a custom wordpress ajax handler? All of these functions are inside my functions.php file. I have a couple of PHP functions that are supposed to pass information from one to another. The an AJAX call to the final function should produce the final result through that call. Its not happening. My count results in 0 and I am not understanding why. If I replace my query with a static array like [44,55,99,33] then it will pass the values ok. Likewise if I keep the query and simply replace the $id in the query and make it a static id such as '20' then it works. I would think that the id was the issue then and it wasnt pulling properly but it seems to work ok just not pass? function idx(){     global $wpdb, $id;       $getId = $_SERVER['REQUEST_URI'];     $ecp = explode('/', $getId);     if($ecp[3] != ''){         $id = $ecp[3];     }         return $id; } add_action( 'after_setup_theme', 'idx' );  =============================================== function Total_Result(){     global $wpdb;     $id = idx();        /*$resultx = [44,88,59,52];*/ ;      $resultx = $wpdb-&gt;get_results( $wpdb-&gt;prepare(&quot;SELECT * FROM {$wpdb-&gt;prefix}custom_form_submission_conversation as cc LEFT JOIN {$wpdb-&gt;prefix}custom_form_submission as cs on cc.fsid ='$id' WHERE fsid='$id'&quot; ));          $resultxs = array($resultx);          $total_result =  count($resultxs[0]);     echo  $total_result; }  when I var_dump $resultx I get: array(3) { [0]=&gt; object(stdClass)#1256 (36) { [“cid”]=&gt; string(3) “167” [“fsid”]=&gt; string(2) “20” [“specified_date”]=&gt; string(3) “yes” [“price_quote”]=&gt; string(4) “1140” [“posted_by”]=&gt; string(9) “dc_vendor” [“limit_count”]=&gt; string(1) “1” [“read_unread”]=&gt; string(1) “1” [“vendor_response”]=&gt; string(4) “zero” [“date_created”]=&gt; string(19) “2021-04-15 11:39:08” }   [1]=&gt; object(stdClass)#1257 (36) { [“cid”]=&gt; string(3) “186” [“fsid”]=&gt; string(2) “20” [“specified_date”]=&gt; string(3) “Yes” [“price_quote”]=&gt; string(3) “602” [“posted_by”]=&gt; string(8) “customer” [“limit_count”]=&gt; string(1) “1” [“read_unread”]=&gt; string(1) “1” [“vendor_response”]=&gt; string(4) “zero” [“date_created”]=&gt; string(19) “2021-04-15 11:39:08” }   [2]=&gt; object(stdClass)#1258 (36) { [“cid”]=&gt; string(3) “188” [“fsid”]=&gt; string(2) “20” [“specified_date”]=&gt; string(3) “yes” [“price_quote”]=&gt; string(4) “1017” [“posted_by”]=&gt; string(9) “dc_vendor” [“limit_count”]=&gt; string(1) “1” [“read_unread”]=&gt; string(1) “0” [“vendor_response”]=&gt; string(4) “zero” [“date_created”]=&gt; string(19) “2021-04-15 11:39:08” } }   so then I try and pass that data like so: function getvendorresponsestatus() {     global $wpdb; $id = idx();          $total_resultx = Total_Result($id);         die; }  Ive tried with and without the die();. The AJAX call is: setInterval(function(){     var ffiidd = jQuery('#ffiidd').val();     var ajaxurl = &quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;;          jQuery.post(ajaxurl, {         action: &quot;vendorAjaxprog&quot;,         ffiidd: ffiidd     }, function(data) {         console.log(data);         jQuery.post(ajaxurl, {             action: &quot;getvendorresponsestatus&quot;, //&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; this is the action that calls the function             fsid : ffiidd         },         function(datas) {             console.log('+ datas);             jQuery('.cust_vendor_top').html(datas);         });         if(data == 0){}else{             jQuery('.ajaxreload').html(data);                                     }     });               }, 5000);/*==30 seconds==*/  So the question is why wont it pass along the query array information but it passes a basic array or it will pass if I change the id in the query to be static? I know the query is good because of when I var_dumped it, I have results before I get to the Total_Result() function.
18799
I have a PHP script that can encode a PNG image to a Base64 string.  I'd like to do the same thing using JavaScript. I know how to open files, but I'm not sure how to do the encoding. I'm not used to working with binary data.
24754
I need an easy way to allow users to upload multiple files at once (ie I need to allow a user to upload a folder).  I do not wish to put the burden of zipping on the user.    I would prefer to avoid Flash or variants if possible.  I'm looking for a straight javascript / HTML solution if it is possible.  Please note, this rules out the answers at: .
29024
I have a custom content type to allow users to upload images.  I'm trying to keep the interface as simple as possible.  The content type contains a single image field.  This works, but some users don't understand that the image has been uploaded because they don't see it after selecting (to preview the upload, the upload button must be pressed).  Is there a way to skip/automatically press the upload button so that an image is shown immediately after a file is selected?  In other words, immediately after selecting a file, instead of the following picture (where the path is shown but hard to read in Firefox):    I'd like the preview display to be shown like this:
88037
So i'm trying to submit a form using ajax, in my form i have the following:          $form['actions']['#type'] = 'actions';         $form['actions']['submit'] = array(         '#type' =&gt; 'submit',         '#value' =&gt; $this-&gt;t('OK'),         '#button_type' =&gt; 'primary',         '#prefix' =&gt; '&lt;div class="tc btn_pay relative"&gt;',         '#suffix' =&gt; '&lt;/div&gt;                         &lt;/div&gt;',         '#attributes' =&gt; array(             'class' =&gt; array('proximabold', 'tc', 'transition', 'no-underline', 'ph3', 'pv2', 'mb2', 'dib', 'white'),         ),         '#ajax' =&gt; [             'event' =&gt; 'click',             'callback' =&gt; '::updateTable',             'wrapper' =&gt; 'table-wrapper',             'progress' =&gt; [                 'type' =&gt; 'throbber',                 'message' =&gt; t('Verifying entry...'),             ],         ],     );   and a simple updateTable function:  public function updateTable(array $form, FormStateInterface $form_state) {     return "Hello World"; }   But when i click on submit i get the error: An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2 MB) that this server supports.  I knew that the error is server side (Maybe i'm wrong), so i went to php.ini (i use PHP7) and update the following lines:  post_max_size = 6144M memory_limit = 6144M upload_max_filesize = 6144M max_file_uploads = 1000   but without luck, this configuration shouldn't be necessary as the request size is only 1.5KB
57784
I'm working on a offline version of a website using jQuery and some xml files. I'm running in to a problem in jQuery when I do a $.ajax call on a xml file jQuery throws a error.  When I look at the error I can tell its loading the XML file because its in the error's responceText property. It seams to work just fine in Firefox.  This is how my call looks  $.ajax({     type: "GET",     url: "Modules/" + ModuleID + "/ModuleContent.xml",     dataType: "xml",     success: function(x) { xml = x; ProcessXML(); },     error: function(x) { alert(x.responceText); } });   When I run this on a web server it works just fine. Its only when I run it from the file its self when I have this problem.  Any ideas on how I can make this work in IE?  Edit: I found the answer to my problem.
122548
I have a submit button in my form and I want to implement it using ajax:  function myid_user_page_form(){      drupal_add_library('system', 'drupal.ajax');     $form = array();     $form['id'] = array(        '#type' =&gt; 'fieldset',        '#title' =&gt; t('ID Information'),        '#prefix' =&gt; '&lt;div id="myid_search_id_number_wrapper"&gt;',        '#suffix' =&gt; '&lt;/div&gt;'    );       $form['submit'] = array(       '#type' =&gt; 'button',       '#value' =&gt; 'Save',          '#ajax' =&gt; array(          'event' =&gt; 'click',          'callback' =&gt; 'myid_user_page_form_ajax_submit',          'wrapper' =&gt; 'myid_search_id_number_wrapper'       ),        '#attributes' =&gt; array(         'id' =&gt; 'myid_save',                    ), );  function myid_user_page_form_ajax_submit($form, &amp;$form_state) {      watchdog('Wow','Wow'); }   After executing the code above, the page still has it's refresh after it's clickfunctionality. The ajax doesnt work and no Wow message log in my watchdog table from my database, which means the ajax callback function isn't called. Where am I missing?
101504
I added this code but when I upload 1 image, then 4 images of 1 image are uploaded, what is happening IMAGES : Not proper working PDF file upload : work fine Doc file upload : work fine rvt file upload : not working Now I am trying to upload multiple files my HTML code is: &lt;input type=&quot;file&quot; name=&quot;my_file_upload[]&quot; id=&quot;my_file_upload[]&quot; multiple=&quot;multiple&quot;&gt;  Code &gt; file custom.php if ( $_FILES ) {  $files = $_FILES[&quot;my_file_upload&quot;];   foreach ($files['name'] as $key =&gt; $value) {                     if ($files['name'][$key]) {              $file = array(                  'name' =&gt; $files['name'][$key],                 'type' =&gt; $files['type'][$key],                  'tmp_name' =&gt; $files['tmp_name'][$key],                  'error' =&gt; $files['error'][$key],                 'size' =&gt; $files['size'][$key]             );              $_FILES = array (&quot;my_file_upload&quot; =&gt; $file);              foreach ($_FILES as $file =&gt; $array) {                               $newupload = my_handle_attachment($file,$pid);              }         }      }  }  Function.php File code function my_handle_attachment($file_handler,$post_id,$set_thu=false) { // check to make sure its a successful upload if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();   require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/image.php');  require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/file.php');  require_once(ABSPATH . &quot;wp-admin&quot; . '/includes/media.php');   $attach_id = media_handle_upload( $file_handler, $post_id ); if ( is_numeric( $attach_id ) ) {   update_post_meta( $post_id, '_my_file_upload', $attach_id );  } return $attach_id; }
98448
I need to submit data to a webform.  I receive data from POST submission from mobile application ("webservices").  So I try something like :   $form_data = array(); $form_data['values']['firstname'] = $user-&gt;field_civilite['und'][0]['tid']; $form_data['values']['lastname'] = $user-&gt;field_prenom['und'][0]['value']; $form_data['values']['mail'] = $user-&gt;field_nom['und'][0]['value'];  webform_client_form_submit(226, $form_data);   But this is don't do anything.  Someone have any idea to do that?
118937
I have a webform on my site and on user submission, I want to send the webform data to some php application that get the value of some variables from the URL.   This task requires me to access the webform submitted data when the user clicks "Submit" button and construct a URL (/myphpapplication?query=....) containing user filled webform values.  Please help me to achieve this.
17677
I have a VF page with file upload control ,Users will upload PDF file along with other details and the file will be stored in Attachments.  Requirement : When user uploads PDF then file should be Water Marked with some text OR some custom text should be included in the header/footer of the file and saved in Attachment object.  What are the options available to acheive this functionality ?  Thanks
91776
I have created a shortcode that retrives and displays a form.The content of the attribute in HTML.   function check_my_login( $atts)     {          return '&lt;form action="" name="" method="post" enctype="multipart/form-data"&gt;                &lt;div class="form-group"&gt;                     &lt;label for="description"&gt;Project Description&lt;/label&gt;                     &lt;textarea name="p_description" placeholder="Project Description" class="form-control"&gt;&lt;?php if (isset($_POST['p_description']) &amp;&amp; $_POST['p_description'] != '') echo $_POST['p_description'] ?&gt;&lt;/textarea&gt;                 &lt;/div&gt;                  &lt;div class="form-group"&gt;                     &lt;label&gt;Project Attachment&lt;/label&gt;                     &lt;input type="file" name="p_attachment"&gt;                 &lt;/div&gt; &lt;/form&gt;';     }     add_shortcode( 'kentaUser', 'check_my_login' );   Now use this shortcode inside the Post/page.   Like this    &lt;div class='manage_page'&gt;[kentaUser]&lt;/div&gt;  But my shortcode content display out side the div.Display upper side in post/page content.  &lt;div class='manage_page'&gt;&lt;/div&gt;    Any one short out this problem.
61504
I am looking for a way to take a user uploaded image that is currently put in a temporary location ex: /tmp/jkhjkh78 and create a php image from it, autodetecting the format.  Is there a more clever way to do this than a bunch of try/catching with imagefromjpeg, imagefrompng, etc?