Return javascript data with form.php

5 replies · opened Sep 19, 2019

Nnicolas33770Sep 19, 2019

Hi awesome support,

I would like some help with your form.php processus please. I need to return data to my page after the form.php was executed. When I send data to form.php I can use my data on php, save them on a database, it's ok... But when I try to return some javascript code, nothing append and the form loader keep loading.

On the form.php at the end you add echo '{ "alert": "success", "message": "test message success" }'; , this code working and the success message was returned.

But if I try to return echo " console.log('test Js console log'); "; or display a new section, that not work ?

Jquery selector is it available ? How can use it to return some JS action to my webpage ?

Nnicolas33770Sep 19, 2019

For exemple I would like :

  • use a "document.location.href" to load the second page on my processus step when the first step is ok.

  • Or use a jquery selector to display block a specific element.

  • Or return a new div element with content to display on the page without reload.

Is it possible to do that with "form-widget" or may be you have another script to do that ?

SSemicolon WebSTAFFSep 20, 2019

Hello,

Thanks for your Patience!

Unfortunately, running a Javascript Request from an AJAX Response is not supported. However, you can consider running your Javascript using a jQuery Event on the Form's HTML Page by adding the following JS code at the bottom of the Page after the js/functions.js JS File Linking:

jQuery('#template-contactform').on( 'formSubmitSuccess', function(){
	// Your JS Codes here
});

or you can redirect the Page to a New Page on Successful Submission by adding the data-redirect="http://your-website.com/thank-you.html" Attribute to the .form-widget Element.

You can check more setup details for the Form in the Documentation > Forms Section.

Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Nnicolas33770Sep 20, 2019

Thanks for your answer, but I need return specific data like "username" to my page. Is it possible to return other data outside of notify ? Do you think we have other way to do that please ?

SSemicolon WebSTAFFSep 22, 2019

Hello,

Unfortunately, this is currently not included by Default and will require somme Customization with the PHP and JS Codes. So, you will need to do this manually. You can consider checking the ajaxForm: function() Function Block in the js/functions.js File to get an idea of how the Data returned from the Form is processed. Simply check for the data.alert and data.message Object Properties and you can use them in your own way to process the output.

Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Nnicolas33770Sep 24, 2019

ok thanks.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard