这是index.php
的页面。
var app = new Vue({
el: '#app',
data: {
jobtype_select: '',
jobtype_list: [{
id_JobType: 'JTY0001',
name_JobType: 'Survey'
},
{
id_JobType: 'JTY0002',
name_JobType: 'Research'
},
{
id_JobType: 'JTY0003',
name_JobType: 'Maintenance'
}
],
joblevel_select: '', //{ id_JobLevel: 'JLE0001', nama_JobLevel: 'Low'},
joblevel_list: [{
id_JobLevel: 'JLE0001',
nama_JobLevel: 'Low'
},
{
id_JobLevel: 'JLE0002',
nama_JobLevel: 'High'
}
]
}
});
<div id='app'>
<form method="post" action="action.php">
<div class="">
<label for="jobtype_id" class="control-label required"><strong>Choose Job Type</strong></label>
<div v-for='jobtype in jobtype_list'>
<label class="">
<input type="radio"
id= 'jobtype_id'
v-model= 'jobtype_select'
:value="jobtype"
name='jobtype_select'
>
{{jobtype.name_JobType}}
</label>
</div>
<p> This is : {{jobtype_select}}</p>
</div>
<div class="form-check">
<label for="joblevel_id" class="control-label required"><strong>Job level</strong></label>
<!-- This is using Vue.JS 2 -->
<div v-for='level in joblevel_list' class="input-group">
<label class="form-check-label">
<input type="radio"
id= 'joblevel_id'
class="form-check-input"
v-model='joblevel_select'
:value="level"
name='joblevel_select'
>
{{level.nama_JobLevel}}
</label>
</div>
<p> This is : {{joblevel_select}}</p>
</div>
<div>
<button>Submit</button>
</div>
</form>
</div>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qs/6.5.2/qs.js"></script>
我正试图从那里将用户输入传递到action.php
,这就是我要做的
<?php
session_start();
var_dump($_POST);
/** Returns
array(2) {
["jobtype_select"]=> string(15) "[object Object]"
["joblevel_select"]=> string(15) "[object Object]"
}
*/
$data = json_decode($_POST['jobtype_select']);
var_dump($data);
// Returns NULL
echo $data; //BLANK PAGE
echo json_decode($data); //BLANK PAGE
echo $data->jobtype_select->name_JobType;
/* Well it's already null
Notice: Trying to get property 'jobtype_select' of non-object in C:\xampp\htdocs\myPlainDashboard\action.php on line 29
Notice: Trying to get property 'name_JobType' of non-object in C:\xampp\htdocs\myPlainDashboard\action.php on line 29
*/
$data2 = $_POST['jobtype_select'];
var_dump($data2);
// Returns string(15) "[object Object]"
?>
我想做的事情:从index.php
检索用户输入值,并能够在action.php
中使用它。它必须是id和名称。如何实现?如果您需要更多信息,请在评论中问我。