2013-08-09 4 views
0

안녕하세요 저는 상쾌하게하지 않고 양식을 제출할 때 몇 가지 문제에 직면하고 있습니다. "반환 거짓"과 관련이 있지만 어디서 어떻게 사용하는지 모릅니다. 나는 (오류가있는 경우) 그것을 배치하여 페이지를 새로 고치려고했지만 그냥 작동하지 않는 것. 너희들이 나를 도와 줄 수 있니?페이지를 새로 고치지 않고 제출을 처리하는 방법

<?php 

    $message = ''; 

    $errors = array(); 

    $noErrors = true; 

    $haveErrors = !$noErrors; 

    require_once('validations/tradeformresult.php'); 
     if ($noErrors && $userArriveBySubmittingAForm) { 

     require_once('price.php');// INSERTION 
     echo "<script type='text/javascript'>\n"; 

      echo "</script>"; 
     echo "<script type='text/javascript'>\n"; 
     echo "alert('Trade is successfully executed!');\n"; 
     echo "</script>"; 



    ///////////MESSAGE///////////////// 
    } 
     elseif ($haveErrors && $userArriveBySubmittingAForm) { 

     echo "<script type='text/javascript'>\n"; 
     echo "alert('Please re-enter your parameters.');\n"; 
echo "return false"; 
      echo "</script>"; 



    } 


    else if ($userArriveByClickingOrDirectlyTypeURL) { // we put the original form inside the $message variable 
     $newTitle = 'The link is broken'; 

     $h1Title = ''; 

     $message = ''; 
    } 
?> 
<!DOCTYPE html> 
<html> 
<head>  
<script type="text/javascript"> 

</script><head><meta charset="UTF-8"></head> 
<style type="text/css"> 

div#overlay { 
    display: none; 
    z-index: 2; 
    background: #000; 
    position: fixed; 
    width: 100%; 
    height: 100%; 
    top: 0px; 
    left: 0px; 
    text-align: center; 
} 
div#specialBox { 
    display: none; 
    position: relative; 
    z-index: 3; 
    p.padding; 

    padding-top:25px; 
    padding-bottom:25px; 
    padding-right:50px; 
    padding-left:50px; 

    margin: 150px auto 0px auto; 

    border: 3px solid blue; 
    outline: 3px solid darkblue; 
    width: 500px; 
    height: 500px; 
    overflow:auto; 
    background: #FFF; 
    color: #000; 
} 
div#wrapper { 
    position:absolute; 
    top: 0px; 
    left: 0px; 
    padding-left:24px; 
} 
</style> 
<script type="text/javascript"> 


function toggleOverlay(){ 
    var overlay = document.getElementById('overlay'); 
    var specialBox = document.getElementById('specialBox'); 
    overlay.style.opacity = .8; 
    if(overlay.style.display == "block"){ 
     overlay.style.display = "none"; 
     specialBox.style.display = "none"; 
    } else { 
     overlay.style.display = "block"; 
     specialBox.style.display = "block"; 
    } 
} 
</script> 
</head> 
<body> 
<!-- Start Overlay --> 
<div id="overlay"></div> 
<!-- End Overlay --> 
<!-- Start Special Centered Box --> 
<div id="specialBox" style="display:none"> 
<script> 

</script> 
<p>Create Order 
    <p><?php 
$timestamp=time(); require_once 'start.php'; 
?> 



<form method="post" name="formSubmitted" **return false;"**> 
<input type="hidden" name="formSubmitted" value="true" runat="server"> 
<?php echo $message; ?> 
<?php ?> 
<?php if ($haveErrors || $userArriveByClickingOrDirectlyTypeURL) : ?> 
    <fieldset> 
<p>Symbol : <select name = "selection" id="selection"> 
<option disabled = "disabled" selected = "selected"> Choose one </option> 
<option value="eur/usd"<?php If($selection=='eur/usd'){Echo 'selected';}?>>EUR/USD</option> 
<option value="usd/jpy"<?php If($selection=='usd/jpy'){Echo 'selected';}?>>USD/JPY</option> 
<option value="usd/cad"<?php If($selection=='usd/cad'){Echo 'selected';}?>>USD/CAD</option> 
<option value="eur/jpy"<?php If($selection=='eur/jpy'){Echo 'selected';}?>>EUR/JPY</option> 
<option value="eur/chf"<?php If($selection=='eur/chf'){Echo 'selected';}?>>EUR/CHF</option> 
<option value="gbp/usd"<?php If($selection=='gbp/usd'){Echo 'selected';}?>>GBP/USD</option> 
<option value="aud/usd"<?php If($selection=='aud/usd'){Echo 'selected';}?>>AUD/USD</option> 
<option value="usd/chf"<?php If($selection=='usd/chf'){Echo 'selected';}?>>USD/CHF</option> 

</select><font color="red"><?php echo $selectionError?></font> 
<p> Date : <input type="datetime" value="<?php echo date("Y-m-d ",$timestamp); ?>"READONLY name="date"/></p> 
<p> Type : <input type="radio" name="type" value="buy"<?php if ($type == 'buy') echo 'checked'; ?>CHECKED> Buy <input type="radio" name="type" value="sell" <?php if ($type == 'sell') echo 'checked'; ?>>Sell<font color="red"><?php echo $typeError;?></font></p> 
<p> Size : <input type="number"pattern="[0-9]+([\.|,][0-9]+)?" step="0.01"min="0"name="size"value="<?php echo $size;?>"/><font color="red"><?php echo $sizeError?></font></p> 
<p> Bid Price (Sell) : <input id="bidprice" READONLY name="bidprice" type="text" value="<?php echo $bidprice;?>"/><font color="red"><?php echo $bidpriceError?></font></p> 
<p> Offer Price (Buy) :<input id="offerprice" READONLY name="offerprice" type="text" value="<?php echo $offerprice;?>"/><font color="red"><?php echo $offerpriceError?></font> </p> 
<p> Stop Loss : <input type="number"step="any"min="0" name="stoploss" value="<?php echo $stoploss;?>"/><font color="red"><?php echo $stoplossError?></font></p> 
<p> Take Profit : <input type="number"step="any"min="0"name="takeprofit"value="<?php echo $takeprofit;?>"/><font color="red"><?php echo $takeprofitError?></font></p> 
</fieldset> 
<div align="center"> 

<input type="submit" value="Submit" Onsubmit =**"return false"**;/><button onmousedown="toggleOverlay()">Close </button> 
</div> 
<input type="reset" name="Reset" value="Reset" tabindex="50"> 
<?php endif; ?> 
</form> 



</script> 



</body> 
</html></p> 

</div> 
</div> 
<!-- Start Special Centered Box --> 
<!-- Start Normal Page Content --> 
<div id="wrapper"> 

    <h2>Trade</h2> 

    <button onmousedown="toggleOverlay();**return false;"**>Create Order</button> 

</div> 


<!-- End Normal Page Content --> 
</body> 
</html> 

<?php 

?> 
+0

정확히 무엇을 하려는지는 잘 모르겠지만 여기서 AJAX/jQuery를 사용하는 것이 더 나을 것이라고 생각합니다. – Maximus2012

+0

백본/백본 양식을 살펴보십시오. – exussum

답변

1

당신이 AJAX를 사용하지 않는 경우, 당신이 정말로 PHP에서이 작업을 수행 할 수 없습니다. 양식이 제출되면 바로 그 것입니다. 간단한 유효성 검사는 브라우저에서 수행 할 수 있습니다. 양식의 제출 이벤트에 유효성 검사 함수를 바인딩하십시오. 그것은 거짓이거나 진실한 것으로 돌아 오는 것입니다.

는 (당신은 물론 서버에서 다시 확인할 것이다.) 당신이 어떤 PHP 코드 (tradeformresult.php)를 실행하려는처럼

0

그것은 당신의 코드에서 보인다. 이런 방식으로로드하는 것은 예상대로 작동하지 않을 것입니다. require_once는 페이지가 PHP가 아닌 브라우저에서 빌드 될 때 실행됩니다.

페이지를 새로 고치지 않고 양식을 보내기를 들어, AJAX ( http://en.wikipedia.org/wiki/Ajax_(programming))

JQuery와 좋은 AJAX 방식을 가지고 조사해야한다. 여기를 사용하는 방법에 대한 간단한 예입니다 : 성공하면 매개 변수, 다음, 서버가 다시 returnData 변수로 준 어떤 데이터를 반환으로

$.ajax({url:"http://www.someserver.com/api/path", 
data:{val1:"value",val2:"value"}) 
.success(function(returnData) { 
    console.log(returnData); 
}); 

은 위의 주어진 데이터를 지정된 URL을 호출합니다.

AJAX를 사용하는 경우 쿼리 문자열을 직접 작성하므로 <form> 태그를 사용할 필요가 없습니다. 단추의 onClick 이벤트에서 AJAX 호출을 트리거하는 기능을 사용할 수 있습니다.

관련 문제