How is this even possible with Javascript?

Published 3 months ago by behnampmdg3

How can Javascript collect email address from a form "without knowing the form id or any other details about the form"?

They claim you can stick a piece of JS on the page and it collects email from the form.

https://www.youtube.com/watch?v=xkyCSAsCYx4

How is this possible?

jlrdw
jlrdw
3 months ago (245,070 XP)

From a fields id I imagine, and looking for the @ symbol. Basic stuff.

Cronix
Cronix
3 months ago (730,880 XP)

You don't need to know the id or any details about the form to select it. You just target the <form> tag(s) itself.

var form = document.getElementsByTagName('form');

Then you just use keyup/down key events to get the input from all of the form fields and run them through regex to find email addresses.

behnampmdg3

And what about submission?

How does it submit the form to different URLs?

Little hint plz

Cronix
Cronix
3 months ago (730,880 XP)

It probably gathers the data it needs, and makes it's own ajax request sending the data elsewhere using the window.onbeforeunload event or something.

Or they target a forms submit action (just like we always do with ajax on our own forms), and when the form is submitted, it also sends the data to another url via ajax.

There really are a lot of ways to do this, but it would really only be able to be done if your server wasn't secure so they can alter/upload files, or your database isn't escaping things properly and they were able to sneak some javascript into a form and the db saved it.

Do you know how much data google scrapes about users when you use analytics? A TON, and all you need to do is include their script on your pages.

behnampmdg3

Ok, I understand you so far.

What I need to know is

1 - on "what event" I collect the email. 2 - How to refer to the form in Jquery without id.

I want to do similar things and my clients do upload any javascript I give them to their page.

All I need at this end is the email field. I need a solid way to capture the emails.

I am gonna try the method above see how far I go. I'll probably post more about it.

Cronix
Cronix
3 months ago (730,880 XP)

$.('form')[0] would give you the first form on the page with jquery.

behnampmdg3

This happens via page builders.

They might have multiple forms on the page.

Maybe there is no robust way to get this 100% right.

Cronix
Cronix
3 months ago (730,880 XP)

Sure there is. You just have to know the DOM, and javascript pretty well. If you don't just want to grab the first form, then leave the [0] off and loop through all of the forms. Or just grab all input fields on the page and ignore the actual form. This isn't that hard, but you have to have enough experience to know what you're doing, and how to do it.

behnampmdg3

Cronix u open to some php jquery job?

Cronix
Cronix
3 months ago (730,880 XP)

Not currently. I've been having to turn down work as there's only so much time.

behnampmdg3

Know anyone good here u could hook me up? Thanks bro

igaster

A simple example...

// Catch the value of the email input field, as user fills the form
$('input[name="email"]).on('change', function(event){

   // Send the input value with an AJAX request to your route
  $.ajax({
    url: "{{route('capture-email-route')}}",
    method: "POST",
    data: {
        "value": $(this).val(), // Input value
    }
  });

});

This would do the trick, but you should also ask yourself if this is legal/ethical etc... You might get some trouble if you store personal data without user approval.

Please sign in or create an account to participate in this conversation.