Jump to content

Recommended Posts

Hey,

 

I want to send some POST data with cURL and then also redirect to the location where Im sending the POST data. Ive been running around like crazy and unable to find a way. This must be something very simple.

Heres what I have thus far, except this doesnt redirect to my target page.

function cURL_post($desturl, $postvalues)
{
$chttp = curl_init($desturl);
curl_setopt($chttp, CURLOPT_POST, 1);
curl_setopt($chttp, CURLOPT_POSTFIELDS, "$postvalues");
curl_setopt($chttp, CURLOPT_FOLLOWLOCATION, 1);
curl_exec($chttp);
curl_close($chttp);
}

 

Any help is much appreciated. Thanks in advance!

mkosmosports

Thanks sKunKbad. However, Im still not able to do what I want to do. It seems cURL is more for communicating with other webpages. Here my situation:

 

-the user fills out a form and submits it to my php script

-my php validation script detects missing or invalid form data, the user gets kicked back out to the form page, and their form fields are now all empty.

 

So here's where my problem lies, I dont want them to have to reenter any other fields they had previously entered, so I thought I would use cURL to send them back to the form page along with a POST request containing any info they had filled in and submitted.

 

Is cURL the way to go here? Does anyone know any alternatives to this situation?

 

Any advice appreciated!

If you really want to do it that way, I'd probably use a $_SESSION array to hold the data from the form. Once the data is in the $_SESSION array, it doesn't go anywhere until it gets unset.

 

On my forms, I use server side validation as a last resort. I use javascript validation for the primary validation. Sure, people can bypass the javascript validation, but if they do, do you really care if you redirect them or not? That's just my 2 cents.

 

I'll PM you a link to my web design home page, and you can check out the javascript.

Yeah, I know sessions would work but I dont want to use them in this case.

 

This is driving me crazy?! With cURL, you can send post requests to pages, so why can I not find anywhere, how to also redirect to the page I sent the POST to. Just like a form POST would do!

 

This has to be possible.

 

 

In my email processing script, the redirect isn't in the curl that posted to the script, it's in the email processing script itself. If the email validates, the script sends them to thankyou.php, and if not it sends them to error.php. My email form on my business site actually has three different redirects based on what happened while the form was being processed. I do this because the user has an checkbox option to sign up for our newsletter, so "thankyou2.php" gives them the confirmation for that.

Can you show me that script sKunKbad? Thanks.

 

In the meantime this will probable be my last bump to this thread. Ive also changed the topic, as maybe this is doable using something else than curl. Here is my ultimate question:

 

Is it possible to simulate a form POST redirect fully with a php script, meaning POST data get sent to a target url and the browser then redirects there as well?

 

Once again, this is part of my form validation. When there is some missing or invalid data, I dont want the user to have to fill everything out again, so I want to post them back the valid data they already entered, and then redirect them back to the form page of course.

 

And I dont want to use hidden forms.

 

 

The only way I know of for ensuring field values are not forgotten when a field doesn't validate is to include the variables in the fields on the page:

 

<?php

if(!isset($_POST['something'])){
  $_POST['something'] = '';
}

?>
<html>
<form> <input name="something" type="text" value="<?=$_POST['something']?>" /> </form>
</html>

 

I'm not a cURL user, but the basic way I think is probably the simplest, though a little long winded for writing out

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.