Forum

Thread tagged as: Question

Form submission with out page refresh.

Hi I am using free Form App in my website and it is working fine . But when I submit the form, the page refreshes or reloads. I want to prevent the page refresh. Is it possible? If not, can I submit the form using JQuery/java script and how?

Damian McCracken

Damian McCracken 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Yes, however you would need to write your own JavaScript to do this. If you need help with JavaScript this probably isn't the best forum.

Ok, thanks no problem.

But I do have another question about it, when I submit the the form using ajax

<script type="text/javascript">
    $("form[name='subscribe-email']").submit(function (event) {
        event.preventDefault();
        $("#msg").html("");
        $.ajax({
            type: "POST",
            data: $("form[name='subscribe-email']").serialize(),
            dataType: "html",
            //timeout: 8000,
            cache: true
        }).done(function (data) {
            if (data.indexOf("SUCCESS") > -1) {
                alert(data);
                document.getElementsByName('emailid')[0].value = "";
                // code for success goes here

            } else {
                document.getElementsByName('emailid')[0].value = "";
                // code for failure goes here

            };
        }).fail(function () {
            // code for failure goes here
        });
        return false;
    });
</script>

Here I need to display success message what ever I have provided in the admin panel. How I will get the response message and display it in the perch? Is there any way possible?

This blog post by Phil Smith might be useful.