Reputation: 115
I was wondering if there was a way to retrieve info from a certain element in HTML and then write it to a file using PHP ?
For example:
<div id="info_needed">text needed</div>
<button id="submit info"> Click to write to PHP file</button>
How would I retrieve the "text needed" and write it to a file using php? (I understand I will have to use the Write()
command, but I am completely lost on how to get the info.
Any help would be awesome.
Thanks guys!
Upvotes: 1
Views: 137
Reputation: 224
Use jQuery to pull the text out. $('#id').text()
Use jQuery.ajax()
to post to a PHP file that does the processing. i.e. capture the posted text.
You can use jQuery.post()
. Make sure you set data parameter. {value: sometext}
Your PHP script can then use file_put_contents()
in append mode to append the text to the file.
P.S.: You could have a success function that indicates the action was successful.
Upvotes: 1