3

On the contact page of my project, I want to send data from a HTML form.
What would you use to send it?
Just the regular <form action="/path/to/handler"> and cause a page refresh or use javascript (jQuery) for it and not cause a page refresh?

In both cases, a message will be shown on success or failure.

Comments
  • 0
  • 0
    @Clear0Ff Any arguments for it?
  • 0
    @FinlayDaG33k i find it easier to connect to a database and store the data. When it's about forms i use php. But depends of the form ofc.
  • 1
    @Clear0Ff Think you might have misunderstood the question at hand.

    It's about the way the front-end sends it to the back-end.

    It will both POST to a PHP script, but I wanted to know what people like better, using the form-action for that, or catching the submission with a listener and send it using Javascript instead.
  • 1
    @FinlayDaG33k
    Usually, add the form action in so the page will refresh, and collect the posted content at the other end for non-Js users, but intercept the form submission with js and post it there with Ajax for a seemless experience where possible.

    Sometimes you may not get the option of the fallbacks depending on the business / project but use them where you can.
  • 1
    $("#formId form").on("submit", function(e){
    e.preventDefault();
    // do your thing
    });
  • 0
    @Zanidd yea, that's what I'm talking about :)

    I'll combine it with what @C0D4 said and use the form-action as a fallback for those bots who don't run Javascript
Add Comment