Drew S Drew S - 3 months ago 9
Javascript Question

pass json object via post along with other data

I am trying to pass 3 variables through post for a basic admin panel for a site.

I have a form like so

var json = {"thing":"stuff"};
var json_file = JSON.stringify(json);

<form action='load.php' method='post'>
<input type='hidden' name='username' value='<?php echo $_POST["username"]; ?>' />
<input type='hidden' name='password' value='<?php echo $_POST["password"]; ?>' />
<input type='hidden' name='json' value='json_file' />
<input type='submit' value='Submit' />

I need the username and password passed along to make sure the person is meant to have access. And the json is meant to be passed on so the PHP script can write it to a file.

I tried wrapping
and using
to write, but its always writing things it shouldn't '�'

  var json = {"thing":"stuff"};
  var json_file = JSON.stringify (json);

<form method='post' onsubmit="this.json.value = json_file;">
    <input type='hidden' name='json'/>
    <input type='submit' value='Submit' />


if (isset ($_POST['username'], $_POST['password'])) {
    if ($_POST['username'] == 'admin' && $_POST['password'] == 'password') {
        // do something