Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Input enter = save data to json file

HTML :

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>test</title>
    <link rel="stylesheet" href="style.css?v=2">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
  </head>
  <body>
    <div class="wrapper">
      <div class="search-input">
      <form method="post" action="store.php">
        <input type="text" placeholder="Type to search..">
        <input type="submit" value="Done"/>
        <div class="autocom-box">
          <!-- here list are inserted from javascript -->
        </div>
        <div class="icon"><i class="fas fa-search"></i></div>
      </div>
    </div>

    <script src="suggestions.js?v=3"></script>
    <script src="js/script.js?v=2"></script>

  </body>
</html>

suggestion.js

let suggestions = [
    "YouTube",
    "YouTuber",
    "YouTube Channel",
    "Blogger",    
];

I need that when the user writes something to the input so that the data is saved and written to json but I don't know how it didn't work for me via php, so I would need help with how to do it in json

store.php

<?php 
$myfile = fopen("suggestions.js", "a+");
$txt = "Login name : ".$_POST['name'].;
fwrite($myfile, $txt); fclose($myfile); 
?>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

$jsonFile = '/path/to/your/json/suggestion.js';
$data = (file_exists($jsonFile))
    ? json_decode(preg_replace('#^let suggestions = \[(.+)\];\s*$#', '$1', file_get_contents($jsonFile)))
    : [];
$data[] = $_POST['name'];
file_put_contents($jsonFile, 'let suggestions = ' . json_encode($data) . ';');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!