How to generate JSON files through forms? [closed]

0

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?

    
asked by anonymous 18.07.2017 / 19:28

2 answers

0

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);
    
19.07.2017 / 19:29
0

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.

    
18.07.2017 / 19:32