cURL - Need to loop an array from $_POST

Discussion in 'PHP' started by mar2195, Jul 8, 2009.

  1. #1
    (*FYI: I am processing a form using cURL.)

    Instead of having to manually enter each incremental line of code in this array, there must be a way to loop this.

    $field1 = 'Contact0FirstName';
    $field2 = 'Contact0LastName';
    $field3 = 'Contact0Email';
    
    $post_data = array(
    $field1=>urlencode($_POST[$field1]),
    $field2=>urlencode($_POST[$field2]),
    $field3=>urlencode($_POST[$field3])
    );
    PHP:

    This doesn't work:
    for($i=0; $i<=2; $i++) {
    	$post_data = array(
    	$field[$i]=>urlencode($_POST[$field[$i]]),
    	);
    }
    PHP:
    ... AND ALSO ...

    Is there a way to receive ALL $_POST input values without specifically entering each input NAME from the form?


    Thanks.
     
    mar2195, Jul 8, 2009 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not sure about your first part but when you say:

    "Is there a way to receive ALL $_POST input values without specifically entering each input NAME from the form?"

    Not sure exactly the result you are looking for, but you can loop through the POST in a foreach as it's an associate array. For example use this loop:
    
    foreach ($_POST as $key => $value){
    echo "Key: $key Value: $value";
    }
    PHP:
     
    wd_2k6, Jul 8, 2009 IP