在php中单击链接时调用php函数
我已经创建了基本的自定义模块。我刚刚填写了信息表,这些信息将存储到数据库中。我将这些数据显示为表格格式。现在我想编辑和删除点击链接的记录 我想在点击以下链接时调用php函数 链接为:在php中单击链接时调用php函数,php,drupal-7,drupal-modules,Php,Drupal 7,Drupal Modules,我已经创建了基本的自定义模块。我刚刚填写了信息表,这些信息将存储到数据库中。我将这些数据显示为表格格式。现在我想编辑和删除点击链接的记录 我想在点击以下链接时调用php函数 链接为: while($data = $result->fetchObject()){ $rows[] = array( $data->id, $data->name, $data->address, $data->mob, $data->gen, $data-&
while($data = $result->fetchObject()){
$rows[] = array(
$data->id,
$data->name,
$data->address,
$data->mob,
$data->gen,
$data->email,
$data->hob,
l('Edit' .$data->id,'/table', array('query' => array('edi'=>$data- >id))),
l('Delete' .$data->id, '/table', array('query' => array('del'=>$data->id))),
);
}
其功能如下:
function form_values_edit($id){
$id_val = $id;
$my_object = db_select('demo_forms','n')
->fields('n')
->condition('id', $id_val )
->execute()
->fetchAssoc();
return drupal_get_form('demo_form', $my_object);
}
function delete_confirm($form, &$form_state, $id){
$form['delete'] = array(
'#type' => 'value',
'#value' => $id,
);
return confirm_form(
$form,
t('Are you sure you want to delete this?',
'/table',
t('This action cannot be undone'),
t('Delete'),
t('Cancel')
));
}
function delete_confirm_submit($form, &$form_state) {
$record = $form_state['values']['delete'];
if ($record ) {
$num_deleted = db_delete('demo_forms')
->condition('id', $record )
->execute();
drupal_set_message('The record has been deleted!');
}
$form_state['redirect'] = "/table";
}
谢谢您不能通过单击链接动态调用PHP函数,因为PHP是一种
服务器端语言
。但是,如果加载另一个页面,在加载该页面之前,可以执行PHP代码
编辑
如果您动态地需要一个PHP函数,我通常会在AJAX
调用中调用该函数。注意:我通常会使用POST来实现这一点
$.ajax(
url: 'url/to/php/function',
type: 'POST/GET',
data: {'data' : data},
success: function(res) {
// use the result stored in res
},
error: function(res) {
// use res to get the error result
}
);
只需在php代码中添加检查id字段或其他唯一值,并更新或删除id=。。。如果没有唯一值,则无法执行此操作。描述你的可用性并发布你的html以获取更多