开发者

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 fo开发者_运维百科rm,

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜