How to access elements from a javascript array for an email sent with PHP/HTML -
So I'm working on a webpage that generates a JavaScript array from the date element of HTML.
This array works fine on its own, and I can print it on a webpage using a command like this:
document.getElementById ("demo "). = Week [0]; To access the generated "Week" array in JavaScript and paste it into the HTML Span element on the webpage
However, it is a webpage that stores data I can not confirm how to get data from this javascript array for email < P> email notifications PHP is formatted using PHP with PHP variables. I thought of using a php array, but I think that whatever solution I am getting for it is either for some other matter or so complex
- I have the ability to copy this JavaScript array into a PHP array, which I would like to break and repurpose.
Can use for email The front.
- The ability to use this JavaScript array within the HTML for the email
This is all contained within a PHP file on the server (HTML markup, JavaScript functions and PHP) < / P>
Edit: I found this thread: and tried your solution with this code: Javascript:
JSON.stringify (week); PHP:
$ datesOfWeek = json_decode ($ _ POST ['week']); But whenever I try to reach the elements of the array and print them in the email, I do not print anything for these elements.
I'm not sure what you want to achieve, but if you want to send data from JS With the form data (on the customer) php script (on the server) you should just sort your array and put it as the value of the additional (hidden) form field. In the PHP script, you can somehow deselect the value of that field (it depends on the format of your choice)
// Edit: Here is a JS Script example that you can use
var myArrayToSend = ["val1", "val2"] var arrayField = document.query selector ("[name = JSRRA]"); Arrayfield.value = JSON.stringify (myArrayToSend) On the server side you only need to deserialize the value of $ _POST ["jsArray"] (use json or library for simple regex Please). Instead of JSON.stringify you can use myArrayToSend.join (";") and then use the partitioning method in pho to "deserialize" that string.
Comments
Post a Comment