Last active
November 23, 2022 00:15
-
-
Save mikestratton/f1f2160fccae791e30b6 to your computer and use it in GitHub Desktop.
Save form data in JSON file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_POST['submit'])) { | |
$file = "data.json"; | |
$arr = array( | |
'name' => $_POST['name'], | |
'email' => $_POST['email'], | |
'phone' => $_POST['cell'], | |
'birthday' => $_POST['dob'], | |
'years' => $_POST['study'] | |
); | |
$json_string = json_encode($arr); | |
file_put_contents($file, $json_string); | |
echo $json_string; | |
} | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<div style="text-align: center;"> | |
<h1>Form</h1> | |
<form name="form1" method="post" action=""> | |
<p> | |
<label for="name">Name: </label> | |
<input type="text" name="name" id="name" placeholder="Your full name" autofocus required> | |
</p> | |
<p> | |
<label for="email">Email: </label> | |
<input type="email" name="email" id="email"> | |
</p> | |
<p> | |
<label for="cell">Cell: </label> | |
<input type="tel" name="cell" id="cell"> | |
</p> | |
<p> | |
<label for="dob">Date of birth: </label> | |
<input type="date" name="dob" id="dob"> | |
</p> | |
<p> | |
<label for="study">Years of art study: </label> | |
0 <input type="range" name="study" id="study" min="0" max="16"> 16 | |
</p> | |
<p style="text-align: center;"> | |
<input type="submit" name="submit" id="submit" value="Submit"> | |
</p> | |
</form> | |
</div> | |
</body> | |
</html> |
Thanks a ton !
…________________________________
From: Mike Stratton <[email protected]>
Sent: Friday, January 17, 2020 6:27:06 PM
To: mikestratton <[email protected]>
Cc: dnyaneshdeshpande2772 <[email protected]>; Comment <[email protected]>
Subject: Re: mikestratton/save2JSON.php
I have updated to remove submit from being inserted into json.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<https://gist.github.com/f1f2160fccae791e30b6?email_source=notifications&email_token=AMUWNUWEX7A3PJDUXYB7NMTQ6GTKFA5CNFSM4KID7QC2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF7XUI#gistcomment-3141444>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AMUWNURHHAWDMGMN3QRTM3DQ6GTKFANCNFSM4KID7QCQ>.
Hi @mikestratton,
Pardon my ignorance, but this is the very first time that I am dealing with PHP and json.
Can you please advise how can the following heirarchy be set up in the array ?
"transactionAmount": {
"total": "1",
"currency": "036"
}
it is not saving multiple json objects. how to do that???
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have updated to remove submit from being inserted into json.