####### SORRY, MY TITLE SHOULD BE: PHP ARRAY FROM DATA - I'm not wanting to use POSTED FORM DATA, I'm using dynamic data called from a database. I just included the form elements here so users could see how the script processes posted data. #######
So I've got this form using a class function. Only I don't want to use the form. I'm just going to call data from a couple of database tables and process it to input into another database, so no posted values. I know I only need 'myfield_2', which will have a dynamic value, and all the others ('myfield_1' and 'myfield_3') will be equal to nothing. I have to use the class unaltered.
How can I express $postFields["myfields"] = array(), much like I've done for $lists? My head hurts much.
The form fields would look like this:
Code:
<input type="text" name="myfield_1" value="" />
<input type="text" name="myfield_2" value="B" />
<input type="text" name="myfield_3" value="" />
Form processor:
PHP Code:
$contactFields = array();
$contactFields["email_address"] = "bob@here.com";
$contactFields["first_name"] = "Bob";
$contactFields["last_name"] = "Smith";
$contactFields["lists"] = array("http://pathtolist.com/contactlistID");
$contactFields["myfields"] = array();
foreach($_POST as $key=>$val) {
if (strncmp($key, 'my_field_', strlen('my_field_')) === 0) {
$contactFields["myfields"][substr($key, strlen('my_field_'), strlen($key)-1)] = $val;
}
}