kostysh / File-uploading-component-for-Sencha-Touch

Ext.Button based component for uploading files in Sencha Touch apps without page refresh
51 stars 26 forks source link

Posting to a wordpress server #1

Closed rbahumi closed 11 years ago

rbahumi commented 11 years ago

Hi,

I am trying to post to a wordpress server, and it requires to send a $_REQUEST['action']='actionname' param. How can I add an extra hidden field with name='action' and value='actionname' to the request ?

I tried adding this line to the fileup.js::initialize() function:

me.formElement.dom.setAttribute('action', 'surf-report-media-submit');

Also, tried to add an extra hidden field to the formelement's children:

{
        tag: 'input',
        type: 'hidden',
        name: 'action',
         value: 'surf-report-media-submit',
         tabindex: -1
},

Both didn't work. Please advice, Roei.

kostysh commented 11 years ago

Adding of your tag template to children of form tag in configuration really produce the new hidden field and this field will be sent to server. Existence of this field you can check with Chrome developer tools. I'm not experimented with requsts to Wordpress in plain Form POST, I don know is it possible at all. But I know that you can work with wordpress thru XML-RPC protocol. My own Sencha for Wordpress XML-RPC solution is not ready, and I can not recommend to use it for your task. May be in next month.

rbahumi commented 11 years ago

I cannot see an additional 'action' variable in Chrome dev tools. I believe that this might be what causing my problem. This is what I see under the Chrome Dev Tools Request Payload:

------WebKitFormBoundarycpf08saZJP5xYBfm
Content-Disposition: form-data; name="base64"

true
------WebKitFormBoundarycpf08saZJP5xYBfm
Content-Disposition: form-data; name="url"

false
------WebKitFormBoundarycpf08saZJP5xYBfm
Content-Disposition: form-data; name="userfile"; filename="Default-PortraitUpsideDown~ipad.png"
Content-Type: image/png

------WebKitFormBoundarycpf08saZJP5xYBfm--
kostysh commented 11 years ago

here is code produced with your added template:

<form target="fileUploadIframe_fileBtn" method="post" enctype="multipart/form-data" action="getfile.php" id="ext-element-18">
<input type="hidden" name="base64" value="true" tabindex="-1" id="ext-element-19">
<input type="hidden" name="url" value="false" tabindex="-1" id="ext-element-20">
<input type="file" name="userfile" tabindex="-1"   style="opacity:0;position:absolute;height:100%;width:100%;left:0px;top:0px;" id="ext-element-21">
<input type="hidden" name="action" value="surf-report-media-submit" tabindex="-1">
</form>

as you can see - your field is exist in html.

and here is request payload:

------WebKitFormBoundaryw1FyABwEnbQzQds9 Content-Disposition: form-data; name="base64" true ------WebKitFormBoundaryw1FyABwEnbQzQds9 Content-Disposition: form-data; name="url" false ------WebKitFormBoundaryw1FyABwEnbQzQds9 Content-Disposition: form-data; name="userfile"; filename="test.png" Content-Type: image/png ------WebKitFormBoundaryw1FyABwEnbQzQds9 Content-Disposition: form-data; name="action" surf-report-media-submit ------WebKitFormBoundaryw1FyABwEnbQzQds9--

as you can see - your field "action" also exist in request