[英]HTML form data to JSON(php)
我正在從服務器通過api將一些數據傳遞到移動設備。為此,我制作了一個html表單,它確實具有文本框,標簽,選擇框等的組合。現在單擊按鈕,我想將所有表單數據轉換為Json格式。這樣做的可能方法是什么。
例如
<label for="register_email">email:</label>
<input type="text" name="email" id="register_email" />
<label for="register_password">password:</label>
<input type="password" name="password" id="register_password" />
<label for="register_password_confirmation">password confirmation:</label>
<input type="password" name="register_password_confirmation" id="register_password_confirmation" />
<input type="submit" value="Register" />
因此,當用戶輸入數據時,單擊后應將表單數據轉換為Json格式。
在您的其他頁面中...
<?php
if(isset($_POST))
{
foreach($_POST as $k=>$v)
{
$params[$k]=$v;
}
echo json_encode($params);
}
你可以試試這個
<form action="your_action_page.php" methd="POST">
現在檢查$_POST
變量。
if(isset($_POST))
{
$json = json_encode($_POST);
echo $json;
}
如果您需要任何進一步的指導,請告訴我...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.