I want to store the data that users put into the inputs into separate JSON files so they can be used later. Can anyone help me?
I want to store the data that users put into the inputs into separate JSON files so they can be used later. Can anyone help me?
If you have taken the data via form, you can use json_encode () before saving the data to the file. Example:
form.html
<form id="form" name="form" method="post" action="save.php">
<input type="text" name="nome">
<input type="text" name="sobrenome">
<input type="submit" value="Enviar">
</form>
save.php (file that receives the form request)
<?php
// Pega a requisição post e transforma em JSON.
$values = json_encode($_POST);
// Armazena no final do arquivo os valores recebidos.
file_put_contents('nome_e_path_do_arquivo.ext', $values, FILE_APPEND);
You can do this with javascript
:
var myJSON = JSON.stringify($("#id_do_meu_form").serializeArray());
The content will be in the myJSON
variable, just use it the way you prefer.