2014-07-15 3 views
0

데이터베이스 값에서 입력 필드 값을 뺍니다. 어떻게 관리해야합니까 ?? MVC에서 필요한 변경 사항은 무엇입니까 ?? myform.ctp 내 코드는 다음과 같이제출 전 입력 값 받기

echo $this->Form->input('discount', array('label' => 'Discount')); 

$val1 = //---------here the input value ---------// 
$val2 = $this->data['Product']['price']; //value from database 
$val3 = $val2 - $val1; 

echo $val3; 

편집 후 :

<?php 
    echo $this->Form->input('discount', array('id'=>'n','label' => 'Discount %','placeholder'=>'Value in %')); 

echo $this->Form->hidden('price', array('id'=>'p')); 


echo $this->Form->input('finalprice', array('id'=>'c')); 

     ?> 
      <script> 

      var a=document.getElementById('n').value; 
      document.write(a); 

      var b=document.getElementById('p').value; 
      document.write(b); 

      var c=b-a; 
      document.getElementById('c').value=c; 
      document.write(c); 

    </script> 

지금 작업을 만들어, 입력 값을 받고 메신저,하지만 난에 최종 값을 삽입해야 데이터베이스 필드 ... data [ 'Product'] [ 'finalprice'] ......... 그 작업을 수행하는 방법은 무엇입니까?

+0

작동하지 않는 기능은 무엇입니까? –

+0

제출하지 않으면 입력 데이터 값을 가져와이 작업을 수행 할 수 없습니다. – rosesfairy

+0

원하는 작업을 명확하게 할 수 있습니까? 사용자가 데이터를 제출하기 전에 양식에서 사용자의 입력 값에 액세스하려고합니까? – KhorneHoly

답변

0

에서 컨트롤러 그리고

$this->set('val1',$this->data['Product']['price']); 

에 값을 설정 beforeSave는 cakephp에서 작동합니다.

+0

마침내 누군가가 나를 이해 .... 나는 또한이 기능을 시도했지만, 무엇이든 놓친 thaaaaaaaaaaaaaaa alooot – rosesfairy

+0

Welcome @rosesfairy – Sadikhasan

0

첫째을 위해 CakePHP에서의 붙박이 기능

public function beforeSave($options = array()) { 
    if (!empty($this->data['Product']['discount']) && 
     !empty($this->data['Product']['price']) 
    ) { 

    $this->data['Product']['finalprice'] = 
      $this->data['Product']['price'] - $this->data['Product']['discount']; 
    } 
    return true; 
} 

확인 Manual 당신의 Product 모델에서 코드 wrie 다음보기

<input type="hidden" value="<?php echo $val1; ?>" id="val1"> 
<?php echo $this->Form->input('discount', array('label' => 'Discount','id'=>'val2')); ?> 



<script> 
    $(document).ready(function(){ 
    var finalval=parseInt($('#val1').val())-parseInt($('#val2').val()); 
    alert(finalval); 
    }); 
</script> 
+0

알 수없는 변수 : val1 – rosesfairy

+0

질문에 내 업데이트를 확인하십시오 – rosesfairy