Reputation: 4028
I have an image upload box like this, which is a part of submission form.
<li id="field_1_14" class="gfield field_sublabel_below field_description_above"><label class="gfield_label">Ảnh</label><div class="gfield_description">Ảnh hàng hóa bạn muốn mua hộ</div><div class="ginput_container ginput_container_fileupload"><div id="gform_multifile_upload_1_14" data-settings="{"runtimes":"html5,flash,html4","browse_button":"gform_browse_button_1_14","container":"gform_multifile_upload_1_14","drop_element":"gform_drag_drop_area_1_14","filelist":"gform_preview_1_14","unique_names":true,"file_data_name":"file","url":"http:\/\/localhost\/?gf_page=5c28261389c3423","flash_swf_url":"http:\/\/localhost\/wp-includes\/js\/plupload\/plupload.flash.swf","silverlight_xap_url":"http:\/\/localhost\/wp-includes\/js\/plupload\/plupload.silverlight.xap","filters":{"mime_types":[{"title":"Allowed Files","extensions":"jpg,gif,png,pdf"}],"max_file_size":"2097152b"},"multipart":true,"urlstream_upload":false,"multipart_params":{"form_id":1,"field_id":14,"_gform_file_upload_nonce_1":"8b58601a9a"},"gf_vars":{"max_files":"10","message_id":"gform_multifile_messages_1_14","disallowed_extensions":["php","asp","aspx","cmd","csh","bat","html","hta","jar","exe","com","js","lnk","htaccess","phtml","ps1","ps2","php3","php4","php5","php6","py","rb","tmp"]}}" class="gform_fileupload_multifile" style="position: relative;">
<div id="gform_drag_drop_area_1_14" class="gform_drop_area" style="position: relative;">
<span class="gform_drop_instructions">Drop files here or </span>
<input id="gform_browse_button_1_14" type="button" value="Select files" class="button gform_button_select_files" aria-describedby="extensions_message" tabindex="4" style="z-index: 1;">
</div>
<div id="html5_1ad7o2aq0k8310031upe1gkr1lqf3_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: 27px; left: 550px; width: 136px; height: 34px; overflow: hidden; z-index: 0;"><input id="html5_1ad7o2aq0k8310031upe1gkr1lqf3" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="image/jpeg,.jpg,image/gif,.gif,image/png,.png,application/pdf,.pdf"></div></div><span id="extensions_message" class="screen-reader-text">Accepted file types: jpg, gif, png, pdf.</span><div class="validation_message">
<ul id="gform_multifile_messages_1_14">
</ul>
</div></div><div id="gform_preview_1_14"></div></li>
When user upload an image test.png by drag/drop or select image from his computer, it will upload the image to server, and the image upload box become like this
<li id="field_1_14" class="gfield field_sublabel_below field_description_above"><label class="gfield_label">Ảnh</label><div class="gfield_description">Ảnh hàng hóa bạn muốn mua hộ</div><div class="ginput_container ginput_container_fileupload"><div id="gform_multifile_upload_1_14" data-settings="{"runtimes":"html5,flash,html4","browse_button":"gform_browse_button_1_14","container":"gform_multifile_upload_1_14","drop_element":"gform_drag_drop_area_1_14","filelist":"gform_preview_1_14","unique_names":true,"file_data_name":"file","url":"http:\/\/localhost\/?gf_page=5c28261389c3423","flash_swf_url":"http:\/\/localhost\/wp-includes\/js\/plupload\/plupload.flash.swf","silverlight_xap_url":"http:\/\/localhost\/wp-includes\/js\/plupload\/plupload.silverlight.xap","filters":{"mime_types":[{"title":"Allowed Files","extensions":"jpg,gif,png,pdf"}],"max_file_size":"2097152b"},"multipart":true,"urlstream_upload":false,"multipart_params":{"form_id":1,"field_id":14,"_gform_file_upload_nonce_1":"8b58601a9a"},"gf_vars":{"max_files":"10","message_id":"gform_multifile_messages_1_14","disallowed_extensions":["php","asp","aspx","cmd","csh","bat","html","hta","jar","exe","com","js","lnk","htaccess","phtml","ps1","ps2","php3","php4","php5","php6","py","rb","tmp"]}}" class="gform_fileupload_multifile" style="position: relative;">
<div id="gform_drag_drop_area_1_14" class="gform_drop_area" style="position: relative;">
<span class="gform_drop_instructions">Drop files here or </span>
<input id="gform_browse_button_1_14" type="button" value="Select files" class="button gform_button_select_files" aria-describedby="extensions_message" tabindex="4" style="z-index: 1;">
</div>
<div id="html5_1ad7o2aq0k8310031upe1gkr1lqf3_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: 25px; left: 186px; width: 136px; height: 34px; overflow: hidden; z-index: 0;"><input id="html5_1ad7o2aq0k8310031upe1gkr1lqf3" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="image/jpeg,.jpg,image/gif,.gif,image/png,.png,application/pdf,.pdf"></div></div><span id="extensions_message" class="screen-reader-text">Accepted file types: jpg, gif, png, pdf.</span><div class="validation_message">
<ul id="gform_multifile_messages_1_14"></ul>
</div></div><div id="gform_preview_1_14"><div id="o_1ad7oetmvfm31gsd11lhsoc1s88f" class="ginput_preview"><img class="gform_delete" src="http://localhost/wp-content/plugins/gravityforms/images/delete.png" onclick="gformDeleteUploadedFile(1,14, this);" alt="Delete this file" title="Delete this file" scale="0"> <strong>test.jpg</strong></div></div></li>
And I found this part of code in form submission, above submit button
<input type="hidden" name="gform_uploaded_files" id="gform_uploaded_files_1" value="{"input_14":[{"temp_filename":"ff301078_input_14_o_1ad7pjak2psd8g4fhpi71ajia.jpg","uploaded_filename":"test.jpg"}]}">
Instead of letting user to upload image like above, I want to:
myimage.jpg is already on server and can publicly access.
Can anybody please help me to do step (2)?
As a result ,when user click form submit button, the image that user actually submit is myimage.jpg.
Thanks.
Upvotes: 0
Views: 188
Reputation: 18987
If all you want is set a image to the box programatically and not let the User upload it. Then you can just use Jquery and set the src
of the image.
var imageSrc = "http://localhost/wp-content/uploads/2015/11/myimage.jpg";
var imageHolder = '<img class="gform_delete" src="'+ imageSrc +'" alt="Delete this file" title="Delete this file" scale="0"><strong>test.jpg</strong>';
$('#gform_preview_1_14').append(imageHolder); // once you append the HTML image will be accessed from the server and loaded.
Upvotes: 1