Do a PHP POST after form POST

Hi there,

When a user fills out my online form i do a Form POST which sends the form data to a url and generates a token.

after that has happened how do i then populate that token into a variable and then do another post ?

What you are describing appears to be a workflow entirely at the browser end. In which case, the answer is ‘use javascript to handle the form post’s return and send another post request out.’

If i’m misunderstanding something, you’ll have to spell it out for me a bit more i’m afraid.

What is the high level overview of what you are trying to solve with this code. It sounds like your logic may be off.

1 Like

Hi sorry its hard to explain so the user on my site will fill out a HTML form then on the submit button that will send that data to a post which will return a success code and a token string.

Then I need to do another post with that token string and more hidden data but all needs to happen on that page.

You could use Ajax to submit the form and get the token string, and use the success() function from that to enable the “real” submit button, which is then used to submit the complete form with token. Or you could use the success() function to handle the complete form submission, so the user doesn’t have to submit twice.

Your describing how you want it to work. I want to know what this is.

1 Like

@droopsnoot Do you have an example on how to do that as the way using the success function so the user doesn’t click twice sounds like this would work perfectly. Thanks for the reply btw

Not off the top of my head, but if you scroll down this forum, and the JavaScript section, there are plenty that would give you enough to build on.

@droopsnoot Thanks for that

I am using this code I created underneath my form but when I hit submit, It puts all the form values in the URL but does not show a response in the console at all

$(function() {
        $(".submit").click(function() {
                url: '',
                type: 'POST',
                contentType: 'application/json',
                data: 'merchantId='. $('#merchantId').val(). '&format=json',
                success: function(msg) {
                error: function() {
                    console.log('ERROR POSTING');

This bit

data: 'merchantId='. $('#merchantId').val(). '&format=json',

doesn’t look correct to me, but you’re asking about JavaScript now, so a post in that section of the forum would be more appropriate I think.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.