Hello! When a user submits a form, I'd like to also include an img src and text from an element on the page.
I think I can accomplish this by saving the img src and text from the dynamic page into local storage, and then passing that into a hidden field which would get submitted along with the user input. But maybe there is an easier way - maybe dynamically submitting the form and having it also include the img src of imageX and text from elementY as part of the submitted data.
If anyone can point me into the right direction, I would really appreciate it!
if you want to include the img src and text from an element on the page when a user submits a form, there are a few approaches you can consider:
Hidden Fields: As you mentioned, you can save the img src and text from the dynamic page into local storage and then pass that data into hidden fields within the form. This way, when the form is submitted, the hidden fields will also be included in the submitted data.
JavaScript Manipulation: You can use JavaScript to dynamically update the form data before submitting it. When the user submits the form, you can extract the img src and text from the respective elements on the page and add them to the form's data before it is sent.
AJAX Requests: Instead of submitting the form traditionally, you can use AJAX to send the form data asynchronously. With AJAX, you have more control over the data being sent, allowing you to include additional information such as the img src and text from the page elements. You can use JavaScript to extract the required data and include it in the AJAX request payload.
Each approach has its own advantages and considerations, so choose the one that best fits your specific requirements and technical expertise. Remember to handle any security considerations, such as properly validating and sanitizing the data before processing it on the server-side on myccpay.