How do I process the result of a form action without redirecting to that form action page?

forms, php

Solution

That is correct, seems like you need to use Javascript and AJAX. With an AJAX call you send an asynchronous post query to that server in the background without redirecting the user to any other pages, and parse the response variables.

If the submit has errors, you can show proper errors (or even add form validations if you know what the server expects and what it doesn't even before submitting it) and if the AJAX call succeeds, just redirect the user to a different page (and don't post the form anymore, since it has already been submitted once)

Problem

Please pardon my lack of 100% specific technical language… I'm a bit of a hack... A backend developer (who's working on a server I don't have access to) has set up a form action for me, and I'm wondering what's the best way to use that form action's response as error or success messages for the user. For example, when I hit the form action with a GET variable (such as remote-server.com/action.cfm?email=nothing) the remote cfm page will display only "-3", which is the error code for "bad email". There are a series of error/success codes the developer has set up corresponding with other error/success cases. So I'm looking for a solution that basically does: Takes the form data and passes it to remote-server.com/action.cfm without directing the user to that page. Reads the response from remote-server.com/action.cfm, which will be a comma-delineated series of numbers. Assign those numbers as a string in PHP, so I can sniff out the error/success codes and display the appropriate messages in my front-end code. So again, the problem in a nutshell is that I want to use form action="remote-server.cfm"... but WITHOUT the page redirecting the user to that cfm page. And instead, it should get the cfm page's output into my form's PHP page so I can process it. Does this make sense? I'm looking around and people seem to say AJAX is the only way to do this. Any other thoughts? Thanks so much!

Original source

Related problems