将JavaScript函数转换为php中的文本文件

I want to save the customer details and order into a text file, this isn't a real online store just an assignment.

The customer enters all their details on the checkout page and clicks submit, this data is then saved to a text file with php. I have a javascript function that saves the order details. I want these 2 things saved in the same text file so I can identify what customer order what. (we haven't used MySQL yet)

Code for Checkout Page The items listed below are currently in your shopping cart:

        <form action="process.php" method ="post">
            <script type="text/javascript">
                CheckoutCart();
                getCartString();

            </script>
            <br /><br />
            First Name:     <input type="text" name="first" /><br />
            Last Name:      <input type="text" name="last" /><br />
            Street Address: <input type="text" name="address" /><br />
            Suburb:         <input type="text" name="suburb" /><br />
            State:          <input type="text" name="state" /><br />
            Postcode:       <input type="text" name="postcode" /><br />
            Country:        <input type="text" name="country" /><br />
            Phone Number:   <input type="text" name="phone" /><br />
            Email:          <input type="text" name="email" /><br />


            shop:           <input type="text" name="shop" /><br />
            <br /><br />
            Other form data can go here when you create your prototype cart ...
            <br /><br />

            <input type="submit" name="submitButton" value=" Submit Order " />
        </form>
        <!-- Checkout End --

This is the code for the process.php file

<?php
if (isset($_POST['submitButton'])) {
file_put_contents('./data.txt', $_POST['shop'] . " " .$_POST['first'] . " " . $_POST['last'] . "
" . $_POST['address'] . "
" . $_POST['suburb'] . " " . $_POST['state'] . " " . $_POST['postcode'] . "
" . $_POST['country'] . "
" . "
", FILE_APPEND);
}
?>

I want the order details saved in getCartString() to be saved in the text file first, I don't think I can mix javascript and php up together so what would the best way to do this be? Can I save the order details to a hidden text box, then it would be posted along with all the customer details too?

At the moment I can write all the customer details to the text file and console.log(getCartString()) shows the order details I just can't figure out this last step of writting them both to the text file.

You're right about javascript not being able to do server-side things.

Either post the info to a php page with a regular form, or use a jQuery AJAX function to post it to your php page.