I'm using CodeIgniter to validate form data, and then posting it to a third party site using the php header() function with the $_POST key-value pairs as URL parameters. So for example:
'first_name' => 'chris' 'area_code' => '555' 'phone_number => '555-5555'
... would become 'http://thirdpartysite.com?first_name=chris&area_code=555&phone_number=555-5555'.
The most "elegant" way I can think to do this is to iterate over the $_POST array like this...
$formValues = $this->input->post(NULL, TRUE);
foreach($formValues as $key => $value)
{
$postURL .= $key . '=' . $value . '&';
}
The problem is that the third party site needs to take a whole phone number as one parameter; it can't take "area code" and "phone number" broken up into two pieces as I have it on my form. So what I need to do is concatenate area_code and phone_number and store it in a new variable that gets appended to the URL string.
What's the best way to do this? I was thinking of maybe adding an if, else statement to the foreach loop that would check if the key is "area_code" or "phone_number" and do the proper actions, but is there a better way to do this? Is there a native way in php or CodeIgniter to modify the $_POST array before iterating over it?
Thank you!!