1

need a little help with this one.

I have a form that I am validating using the "form_validation" library in codeigniter, obviously the form action is pointing to itself for validation (as it should) but i need to submit to an external url, with the post data included, if validation successful.

CURL is not an option as i need the user to also be redirected to that page and GET method is also not an option as the data needs to be POSTed!!

it almost needs a function like PHP redirect() that you can attach an array of post data to.

ideal world = redirect('https://payment.bank.com', 'method: POST', $data_array);

if there is no way to do this i may have to invent it, but want to ask the question first before i go re-iventing the wheel (it will also take a considerable amount of time, i guess)

EDIT: also note javascript is also not an option as the site needs to work with or without javascript enabled!!!!!

2 Answers 2

1

This is not possible the way you describe it, as PHP is server side, and it would be the SERVER submitting the data, NOT the user, so the redirect to that data would NOT be possible.

You could CURL the data, then redirect based on a 'reference' from the foreign server (say submission ID).

However the most simple approach would be to do this:

  • Validate the data like you are doing right now
  • Loading a new FORM page with all that data loaded & hidden in a new form
  • that new loaded form page would say something like "Validated, click to continue if you are not automatically redirected" (which would submit the form), at this point use Javascript to submit/redirect, OR as a fallback people would click the button.
  • Data then is validated by you initially (captured / modified / augmented) and then prepared for transport to the foreign host with a tiny delay.

Keep in mind if you are doing a post like this without permission, the foreign post might have cross domain submission checking (say abc.com not allowed to submit to xyz.com).

Hope that helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Ahhhhh reading your comment sparked something off in my head, the bank that we need to redirect to can send a token back to the CURL function that I can use in a GET var inside a redirect, I would of forgot that if I hadn't read your post, sometimes it's easy to over engineer an problem. Cheers buddy
Glad it worked, sometimes just writing out your problem I find helps you get the correct answer.
0

You can do it using ajax i guess. submit your form for validation in the background. If valid, using javascript resubmit the same form to the external url.

1 Comment

yeah, that is the only solution i can come up with but my client needs the site to work with or without javascript enabled (pain the arse if you ask me, if you have javascript disabled you shouldnt use the internet, just my opinion)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.