0

Why this form wont submit?

<div data-dojo-type="dijit/form/Form" id="myForm" data-dojo-id="myForm"
encType="multipart/form-data" action="Cart.php" method="post">
<input type="text" name="searchName" 
data-dojo-type="dijit/form/TextBox"
data-dojo-props="trim:true, propercase:true" id="searchName" />
<input type="radio" data-dojo-type="dijit/form/RadioButton" name="sl" id="radioOne"    value="full"/> <label for="radioOne">Full</label>
<input type="radio" data-dojo-type="dijit/form/RadioButton" name="sl" id="radioTwo" value="short"/> <label for="radioTwo">Short</label>
Data Select
<select name="select1" data-dojo-type="dijit/form/Select">
<option  value="2">Data1</option>
<option  value="1">Data2</option>
</select>
<button data-dojo-type="dijit/form/Button" type="submit" name="submitButton"     value="Submit">Submit</button>
</div>

Some javascript too:

    <script src="//ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/dojo.js" data-dojo-config="parseOnLoad:true"></script>
    <script type="text/javascript">
dojo.require("dijit.form.Form");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.TextBox");
dojo.require("dijit/layout/AccordionContainer"); 
dojo.require("dijit/layout/BorderContainer");
dojo.require("dijit/layout/ContentPane");
    </script>

Maybe its a stupid question, but ive been looking at it several hours and still cant figure it out. Thanks in advance

1 Answers1

0

I'm not sure what do you meet by won't submit. I moved your code into JS Bin (http://jsbin.com/iziwen/1/edit) and it works fine:

enter image description here

If you experience problems on the server side I suggest you change encType="multipart/form-data" to enctype="application/x-www-form-urlencoded" (or do not use it at all as it is the default value) - you do not need multipart/form-data, you are not sending files (see more here).

If this won't help, please specify won't submit more precisely.

EDIT: I do not use dijit/form/Form submit functionality, I just grab form data and send those via XHR to my web service, but I had a look at how submit functionality works and it seems so you need an <iframe> to use submit functionality. So this is what I changed:

A. Form definition - target:"formSubmitIframe" points to iframe id:

<form
    id="myForm"
    data-dojo-id="myForm"
    data-dojo-type="dijit/form/Form"  
    data-dojo-props="action:'Cart.php', method:'post', target:'formSubmitIframe'"
>

B. Added iframe:

<iframe name="formSubmitIframe" src="about:blank"></iframe>

Once all works for you add style="display:none;" to iframe to hide it.

See it in action in JS Bin: http://jsbin.com/iziwen/7/edit

N.B.: I do not recommend submitting a form this way. If you do not need to go cross-domain or sending files, simply get form data via var data = dijit.byId("myForm").get("value"), so you will have form data in JSON and then send them up via dojo/xhr or dojo/request (for dojo 1.8+).

Also dojo/xhr is capable to send form just by providing a form id to it - here is a nice example: http://livedocs.dojotoolkit.org/dojo/xhr

Community
  • 1
  • 1
phusick
  • 7,342
  • 1
  • 21
  • 26
  • Oh sorry, by wont submit i mean that doesnt jump to action (cart.php) and dont know why. Im kind of new with DOJO, maybe i need something extra in the javascript part? –  Aug 30 '12 at 10:08
  • Submitting form this way does not seem to be the best choice. I edited my answer to provide alternatives. Hope it will help. – phusick Aug 30 '12 at 10:58