简体   繁体   中英

Mootools - How to create a form and submit this form?

My idea : when click a filename will get the path of file ,

then create a form and submit this form,

but i don't know how to submit ,

when submit , undefined form cause elements was created at same time

help me, thank !

<p onclcick='startUpload(this.value)'>PATHTOFILE<p>

function startUpload(file)
        {
          var form = '<form name="form_upload" method="post" enctype="multipart/form-data" action="upload.php">';
          form +=   '<input type="file" name="upload_logo"/>';
          form += '</form>';

          // code to submit . i don't know how :(
        }

first off, p tags have no value . this.value needs to change to this.get("text").clear(); second, you cannot pass on the value to the file dialogue object from an external source - else, what's to stop you from changing that value to say, c:\\autoexec.bat or /etc/passwd or similar, you get the idea - a major security flaw in the design.

so the form creation is fine but it needs to be user driven - they select the file, they submit (or you submit on select for the file input).

to plain submit using your current html you'd do:

new Element("div", {
    htm: form
}).inject(targetDiv);

targetdiv.getElement("form[name=form_upload]").submit();

if you need to ajax it, then say so - there are some methods available through html5 or an iframe shin or a flash uploader that can allow you to do so without a page reload, neither of which qualifies for progressive enhancement though.

good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM