Search code examples
javascriptjqueryimgur

How to insert the value in a field added manually without the script imgur generating another?


I am using imgur's library to upload images, I have it running here without any inconvenience: jsfiddle the only problem I present is with the validation of PHP, that when the form field is generated, php does not detect it, It is because, the following field: <input name="cover_page" class="image-url" value=""> is only generated when an image is uploaded

To avoid this problem I want to add the following field <input name="cover_page" class="image-url" value=""> in a manul way, and that the script inserts the value when uploading the image in it without the script generating me another input

How can I do this?


Solution

  • Hi for the other part you can add manually the input inside the form '#news'

    i see you do have input cover_page in your page replace it with this

    <input id="IMG_URL"name="cover_page" class="image-url" value=""/>

    then after upload change it's value then frm.serialize will upload cover_page

    replace feedback function with this

    var feedback = function(res) {
      if (res.success === true) {
        var get_link = res.data.link.replace(/^http:\/\//i, 'https://');
        document.querySelector('.status').classList.add('bg-success');
        document.querySelector('.status').innerHTML = 'Image : ';
        document.querySelector('.loading-image').src = res.data.link;
    
        $('#IMG_URL').val(res.data.link);
    
      }
    };