tags:

views:

66

answers:

3

What I'm trying to do is:

I have a form. I submit that form. In the code of the target script I want to make some validations. In a certain case, I want to make a POST to another URL. I don't want to just make a redirect to an URL.

I don't know if this is possible, that's why I'm asking.

I'm working with PHP.

Thanks!

A: 

In what case would you need to post it to another PHP file.

Couldn't you simply use IF statements to redirect the script to another script depending on the results of the validation?

Noctine
i can't redirect to another url in my case
Kstro21
A: 

It is definitely possible. You could use the PHP cURL library to easily create a POST request. But this might be overkill for what you are trying to achieve. Is it a possibiity to do the validation in JavaScript and change the form action attribute with JavaScript after submitting?

Martijn Dwars
in my case, i already validate the form wth javascript, the problem is that i will send sensitive information, and i don't want to put it into the form html.
Kstro21
+2  A: 

To the people who suggested cURL: Building a request like so will send the data on behalf of the server not the client. I don't think he wants that.

He wants POST forwarding and that, if it were to exist (and I don't think it does), should be implemented by the browser.

What I suggest is to use an AJAX call to make the validation before posting. And then depending on the response you choose the destination for posting (on the client side).

To summarize: You request a validation from the client. You do that validation on the server. You send back instructions to the client. You post according to the instructions received from the server.

I'm not sure if you understand this, but any details of requests made by the user(client) are known in full by him. You can't make him POST to an URL, have a password in that POST, and not have access to that password.

Note: If it's easier you can read JavaScript and PHP instead of client and server.

Alin Purcaru
If he wants to hide sensitive data, he can't do this browser-side.
ceejayoz
Please read the whole answer. I suggested an AJAX request to the server. He only sends back what's needed for the correct POST (probably just the new URL). And that is definitely not sensitive data.
Alin Purcaru
what about if i don't want some information to be in the html form?
Kstro21
You want to make the user do a POST. Isn't that right? Anything you put in that POST should be known to the user because is his request (If you have firebug check the Net tab. You'll see there all you requests, including POSTs). If you don't want to give away the details of the request then you should make the request yourself in the background and feed the response to the user.
Alin Purcaru
how can i make that, make the request myself in the background and feed the response to the user?
Kstro21
Yes. With cURL. But the user won't leave you page. It all depends on what you want to do.
Alin Purcaru