dsyct08008 2012-04-30 09:00
浏览 131

单击按钮时调用php函数

i have a form..when i click the insert button the values has to be store in database.. but in my form when i open the form the default values are storing in db.i am developing all these in php mvc architecture.

this is my controller:

 <?php
        class ControllerSaleAd extends Controller {
private $error = array();

         public function index() {

    $this->load->language('sale/ad');


    $this->document->setTitle($this->language->get('heading_title'));


$this->data['heading_title']=$this->language->get('heading_title');
$this->data['entry_customer_name'] = $this->language->get('entry_customer_name');
$this->data['column_name']=$this->language->get('column_name');
$this->data['column_place'] = $this->language->get('column_place');
$this->data['column_date'] = $this->language->get('column_date');

$this->data['column_units'] = $this->language->get('column_units');
$this->data['column_price'] = $this->language->get('column_price');
$this->data['button_insert'] = $this->language->get('button_insert');


$this->data['breadcrumbs'] = array();

$this->data['breadcrumbs'][] = array(
            'text'      => $this->language->get('text_home'),
            'href'      => $this->url->link('sale/ad', 'token=' . $this->session->data['token'], 'SSL'),
            'separator' => false
);

$url='';
$this->data['action'] = $this->url->link('sale/ad', 'token=' . $this->session->data['token'] . $url, 'SSL');

$this->template='sale/ad.tpl';
$this->children = array(
            'common/header',
            'common/footer'
);


$this->load->model('sale/ad');






$this->insert();

$this->response->setOutput($this->render());
      }

public function insert() {



    $customer = $_POST['entry_customer_name'];
    $adtype = $_POST['column_name'];
    $adplace=$_POST['column_place'];
    $date=$_POST['column_date'];
    $units=$_POST['column_units'];
    $price=$_POST['column_price'];


    $data=array();

    $data = array (

     'customer' => $customer,
     'adtype'  =>  $adtype,
     'adplace'  => $adplace,
     'date'     => $date,
     'units'    => $units,
     'price'    => $price,
    );


$this->model_sale_ad->insert($data);
    }

}




      ?>

when i click the insert button the insert() function has to be called.... help me how to write like that...

  • 写回答

1条回答 默认 最新

  • douqihou7537 2012-04-30 12:20
    关注

    Your ideas seem to be a bit confused. You can't run PHP code on client-side (ie: when a user click a button)

    What you can do is an AJAX call to your php page that will insert your records.
    Many of current frameworks have libs to manage AJAX action easly.

    You can read further here: http://en.wikipedia.org/wiki/Ajax_(programming)

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法