Preload file in input type = 'file'

0

Is there any way that an html input file contains a preloaded file when the form is displayed? What I intend is that in a configuration form, the fields saved by the user (stored in the database) are preloaded when you access the form again.

Thank you!

Template twig

{% for input in inputs %}
    <label>  
    {% set string = input.tag %}
    {% set string = string|replace({'_': ' '}) %}
    {{string}}
    </label><br>
    {% if input.codigo == 'number' %}
        <input type="number" name={{input.tag}} value={{input.tag}} id="{{input.tag}}">
    {% elseif input.codigo == 'text_strong' or input.codigo == 'text_simple' or input.codigo == 'link' %}
        <input type="text" name={{input.tag}} value={{input.tag}} id="{{input.tag}}" >
    {% elseif input.codigo == 'imagen' %}
        <input type="file" accept="image/*" name={{input.tag}} value={{input.tag}} id="{{input.tag}}">
    {% elseif input.codigo == 'text_long' %}
        <textarea maxlength="400" name={{input.tag}} id="{{input.tag}}"style="resize: vertical;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
        </textarea>
    {% endif %}
{% endfor %}

Once the data is collected by ajax, I go through the array

$.each($values,function(index, el) {
        // Compruebo tipo de input (1,2,3,5,7 = texto) 4=file 6=link
        if(el.tipo_field_id == 1 || el.tipo_field_id == 2 || el.tipo_field_id == 3 || el.tipo_field_id == 5 || el.tipo_field_id == 7){ 
            $('#'+el.tag).val(el.texto);
        }else if(el.tipo_field_id == 4){
            //Cargar el fichero;
        }else if(el.tipo_field_id == 6){
            $('#'+el.tag).prop("href" , el.texto);
        }
    });
    
asked by Pablo León 22.05.2018 в 12:15
source

1 answer

0

by security issues I do not think browsers will allow it, but what you can do is have a input type="hidden" that has as value the url of your file on the server and before sending the form if the value of input type="file" is empty you take the data from the URL of the hidden

    
answered by 22.05.2018 в 13:20