1

I have a login form created in Wordpress using Contact form 7. I'm tryig to pass parameters from this form to an external server. But it is not happening.

I am a designer, and not much of a programmer. I understand code(sometimes) but can not write it from the scratch. I have designed a website for a client. This client has a "Flying Returns" like logistic membership system in which members get lots of perks in shipping etc. This system is on their own server. They want the users to log in to that system from this website.

So I have created a login form using Contact Form 7. I have set skip_mail: on; I have tried a few plugins login, but either they dont log into different servers or are expensive, or does not yield correct URL and hence does not log into the system. Therefore I have finally decided to make it happen using code.

Their programmer has given me following JS code that will take the parameters from this form and pass on to their system. IF the parameters are correct, then the user is logged into the system and taken to the member's dashboard page on their server (not my website/server), else it returns an error message, {"error":"Login Data Incorrect.."} I have tried to put this code with in the contact form. Here is the code (i've hidden the actual IP address, sorry):

<script>
document.addEventListener( 'wpcf7submit', function( event ) {
alert( "Fire!" );
document.location.href="http://49.XXX.XXX.202:XXXX/glslink/servlet/GPLogin?password="+$('#password').val()+"&emailid="+$('#emailid').val();
}, false );
</script>

If I remove the document.location line, it shows the alert. But the above, in its entirety does nothing. If I use the URL, replace variables with actual values and paste it browser, it logs me into the system without a hitch. I have tried quite a few different codes which I could find as possible solution on internet, this site including, but to no avail.

Please help me out. I want the email and password to be passed to this external server, if they are correct then the user should log in and see their dashboard there. Else if it gives the above mentioned error message, then I should be able to reset the form and give an error message to the user.

8
  • Did you try this plugin? wordpress.org/plugins/cf7-to-api
    – jasie
    Commented Jan 18, 2019 at 8:22
  • Hey @Jasie, Thanks for the suggestion. I tried it now, but it too does not work. I checked the log it comes with and it gives following error: [0] => cURL error 7: Failed to connect to 49.248.28.202 port 8095: Connection refused
    – Ashwin
    Commented Jan 18, 2019 at 11:11
  • Good. Well, if the server is not reachable, your JS code cannot pass contact form 7's parameters there... Can you reach this server otherwise?
    – jasie
    Commented Jan 18, 2019 at 11:28
  • Update: I managed to get it working, but I had to install their second plugin wordpress.org/plugins/wpcf7-redirect However, if the login credentials are incorrect, and it returns the jason {"error":"Login Data Incorrect.."} , could you please tell me how to I show the error message on my login screen?
    – Ashwin
    Commented Jan 18, 2019 at 11:39
  • Congrats! But Stack Overflow is not a free coding service. You gotta try for yourself, first. If you fail, write a new issue.
    – jasie
    Commented Jan 18, 2019 at 12:10

0