0

I'm trying to output the form elements and values entered by the user to a YAML file. I'm using Spyc to parse and dump the code, but I'm not married to that if there's another way. Here's what I have so far:

include('Spyc.php');
if(isset($_POST['submit'])) {
  $file = "data.yaml";
  $yaml = Spyc::YAMLLoad($_POST);
  $yaml_out = Spyc::YAMLDump($yaml);
  file_put_contents($file, $yaml_out, FILE_APPEND);
  header('Location: thanks.php'); 
}

When I run the page, all I get is:

---

which is the opening syntax for YAML, but no actual data. Am I getting the $_POST array incorrectly?

As always, any help is greatly appreciated.

Best - Joe

1 Answer 1

1

Figured it out. Didn't need the load command at all.

include('Spyc.php');
if(isset($_POST['submit'])) {
 $file = "data.yaml";
 unset($_POST['submit']);
 $yaml = Spyc::YAMLDump($_POST);
 file_put_contents($file, $yaml, FILE_APPEND);
 header('Location: thanks.php'); 
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.