PDA

View Full Version : مشکل در فرم



hassan68
سه شنبه 29 فروردین 1391, 13:31 عصر
سلام دوستان
این فرم رو نگاه کنید گزینه submit داره وقتی این گزینه داشته باشه تا فرم submit نشه عکس نشون نمیده ولی وقتی submit اونو برداریم خوذش خوذکار آپلود مشه عکس و بهمون نشون میده
حالا مشکل اینجاست که من میخوام گزینه submit باشه و عکس هم خودکار آپلود بشه


<form action="scripts/ajaxupload1.php" method="post" name="sleeker" id="sleeker" enctype="multipart/form-data">
<input type="hidden" name="maxSize" value="9999999999" />
<input type="hidden" name="maxW" value="200" />
<input type="hidden" name="fullPath" value="http://localhost/php_ajax_image_upload/uploads/" />
<input type="hidden" name="relPath" value="../uploads/" />
<input type="hidden" name="colorR" value="255" />
<input type="hidden" name="colorG" value="255" />
<input type="hidden" name="colorB" value="255" />
<input type="hidden" name="maxH" value="300" />
<input type="hidden" name="filename" value="filename" />
<p><input type="file" name="filename" onchange="ajaxUpload(this.form,'scripts/ajaxupload.php?filename=name&amp;maxSize=9999999999&amp;ma xW=200&amp;fullPath=http://localhost/php_ajax_image_upload/uploads/&amp;relPath=../uploads/&amp;colorR=255&amp;colorG=255&amp;colorB=255&amp;maxH=300','uploa d_area','File Uploading Please Wait...&lt;br /&gt;&lt;img src=\'images/loader_light_blue.gif\' width=\'128\' height=\'15\' border=\'0\' /&gt;','&lt;img src=\'images/error.gif\' width=\'16\' height=\'16\' border=\'0\' /&gt; Error in Upload, check settings and path info in source code.'); return false;" /></p>
<p><input type='submit' name='submit' value='go'></p>

</form>
</fieldset>

</div>
<div id="right_col">
<div id="upload_area">
Images Will Be uploaded here for the demo.<br /><br />
You can direct them to do any thing you want!
</div>
</div>


اینم فابل جاوا اسکریپت



function $m(theVar){
return document.getElementById(theVar)
}
function remove(theVar){
var theParent = theVar.parentNode;
theParent.removeChild(theVar);
}
function addEvent(obj, evType, fn){
if(obj.addEventListener)
obj.addEventListener(evType, fn, true)
if(obj.attachEvent)
obj.attachEvent("on"+evType, fn)
}
function removeEvent(obj, type, fn){
if(obj.detachEvent){
obj.detachEvent('on'+type, fn);
}else{
obj.removeEventListener(type, fn, false);
}
}
function isWebKit(){
return RegExp(" AppleWebKit/").test(navigator.userAgent);
}
function ajaxUpload(form,url_action,id_element,html_show_lo ading,html_error_http){
var detectWebKit = isWebKit();
form = typeof(form)=="string"?$m(form):form;
var erro="";
if(form==null || typeof(form)=="undefined"){
erro += "The form of 1st parameter does not exists.\n";
}else if(form.nodeName.toLowerCase()!="form"){
erro += "The form of 1st parameter its not a form.\n";
}
if($m(id_element)==null){
erro += "The element of 3rd parameter does not exists.\n";
}
if(erro.length>0){
alert("Error in call ajaxUpload:\n" + erro);
return;
}
var iframe = document.createElement("iframe");
iframe.setAttribute("id","ajax-temp");
iframe.setAttribute("name","ajax-temp");
iframe.setAttribute("width","0");
iframe.setAttribute("height","0");
iframe.setAttribute("border","0");
iframe.setAttribute("style","width: 0; height: 0; border: none;");
form.parentNode.appendChild(iframe);
window.frames['ajax-temp'].name="ajax-temp";
var doUpload = function(){
removeEvent($m('ajax-temp'),"load", doUpload);
var cross = "javascript: ";
cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
$m(id_element).innerHTML = html_error_http;
$m('ajax-temp').src = cross;
if(detectWebKit){
remove($m('ajax-temp'));
}else{
setTimeout(function(){ remove($m('ajax-temp'))}, 250);
}
}
addEvent($m('ajax-temp'),"load", doUpload);
form.setAttribute("target","ajax-temp");
form.setAttribute("action",url_action);
form.setAttribute("method","post");
form.setAttribute("enctype","multipart/form-data");
form.setAttribute("encoding","multipart/form-data");
if(html_show_loading.length > 0){
$m(id_element).innerHTML = html_show_loading;
}
form.submit();
}

MMSHFE
سه شنبه 29 فروردین 1391, 15:30 عصر
type دكمه رو بجاي submit بگذارين button و توي رويداد onclick براش يك تابع بنويسيد كه فرم رو Submit ميكنه.

hassan68
سه شنبه 29 فروردین 1391, 19:54 عصر
یک نمونه تابع میزارید
چون فرم اصلی این نیست و خیلی تغییرات باید بدم
یک مثال بزنید ممنون میشم
به نظرتون خوبه اینو برای کل فرم استفاده کنم



<form name="form1" method="post" action="act_load_structure.cfm">
<input type="text" name="name">
.....
</form>

<a href="##" onClick="fn_submit();" >Submit</a>

<script>
function fn_submit()
{
document.form1.submit();
}
</script>

MMSHFE
چهارشنبه 30 فروردین 1391, 10:13 صبح
بله همین کافیه.

hassan68
چهارشنبه 30 فروردین 1391, 19:34 عصر
آقا اینو تست کردم بازم نشد وقتی دکمه submit میزنم کل فرم رو بیخیال میشه میره به مسیری که عکس آپلود شده

MMSHFE
پنج شنبه 31 فروردین 1391, 10:52 صبح
خوب این که action فرم عوض شده. قبلی ajaxupload1.php بود، این یکی اطلاعات رو به یک صفحه Cold Fusion میفرسته. اگه میشه کد کامل رو بگذارین. اینطوری تکه تکه نمیشه کار کرد. دقیقاً مشکل نیست کدتون چیه و چطور داره کار میکنه.