我用這個片段從外部數據庫中獲取車輛數據的數據:而不是提交獲得進入頁面PHP
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>" class="vwe-kenteken-widget">
<p><input type="text" name="open_data_rdw_kenteken" value="<?php echo $_POST['open_data_rdw_kenteken'] ?>" maxlength="8"></p>
<p><input name="submit" type="submit" id="submit" value="<?php _e('Kenteken opzoeken', 'open_data_rdw') ?>"></p>
</form>
<?php if($data): ?>
<h3><?php _e('Voertuiggegevens', 'open_data_rdw') ?></h3>
<table>
<?php
$categories = array();
foreach ($data as $d) {
if(!is_array($fields) || in_array($d['name'], $fields)) {
if(!in_array($d['category'], $categories)) {
$categories[] = $d['category'];
echo '<tr class="open-rdw-header">';
echo '<td colspan="2" style="font-weight: bold;">';
echo '<a href="#">'.$d['category'].'</a>';
echo '</td>';
echo '</tr>';
}
echo '<tr style="display:none">';
echo '<td>'.$d['label'].'</td>';
echo '<td>'.$d['value'].'</td>';
echo '</tr>';
}
}
?>
</table>
<?php endif; ?>
我想要做到的是,該數據未經用戶加載必須輸入值並點擊提交按鈕。輸入值將根據用戶正在查看的產品頁面加載。
編輯:
該數據是基於加載:
public function get_json() {
if (isset($_POST['kenteken'])) {
$data = $this->rdw->get_formatted($_POST['kenteken']);
foreach ($data as $row) {
$json['result'][$row['name']] = $row['value'];
}
if ($_POST['kenteken']) {
if ($data[0]['value'] == '') {
$json['errors'] = __('No license plates found', 'open_data_rdw');
}
else {
$json['errors'] = false;
}
}
else {
$json['errors'] = __('No license plate entered', 'open_data_rdw');
}
header('Content-type: application/json');
echo json_encode($json);
die();
}
}
因此,而不是一個$ _ POST動作只得到基於預先申報價值是每個頁面上不同的數據。
你在哪裏定義$數據?所以,如果我正確地想要在頁面加載時自動提交表單? –
您是否嘗試過使用Ajax? – AJAY
@PuyaSarmidani我編輯了最初的問題。 – RoRo