A bit of background
The project I am working on requires me to build a dynamic form, essentially a page is created and from there a user can add as many news articles to that page as they wish, my issue is that this is an inherited system and I have to jump through a million different hoops, one of which is the string sanitation, they way form is built is that all the news article headlines are put into an array in the post and the same happens with the article content. The $_POST
with one news headline and one article basically looks like this.
array(5) {
["campaign_title"]=>
string(16) "Newsletter title"
["campaign_keyword"]=>
string(7) "Thearte"
["campaign_headline"]=>
array(1) {
[0]=>
string(19) "Newsletter Headline"
}
["article"]=>
array(1) {
[0]=>
string(22) "Newsletter article<br>"
}
["save_single"]=>
string(4) "Save"
}
The problem
My problem is during the process of saving to the database the POST gets validated and sanitized. Firstly is goes to this function
function preformatMailerData($post) {
extract($post);
$d = array();
$d['campaign_title'] = preformatPostTextfield($campaign_title);
$d['campaign_keyword'] = preformatPostTextfield($campaign_keyword);
return $d;
}
Then is goes onto this function to make that the data entered is valid and no empty fields are left,
function assessMailerData($data) {
extract($data);
$errs = array();
if ($campaign_title == '') $errs[] = 'Enter the campaign title';
//if ($mailerType == '') $errs[] = 'Choose a campaign type';
if ($campaign_keyword == '') $errs[] = 'Enter the campaign keyword';
//die(print_r($errs));
return $errs;
}
My issue is that the function preformatPostTextfield() does not allow for arrays, which means that validate them I must run a foreach loop. This is where my problem begins, my problem that doing this puts each headling and article into its variable. What I need to happen is make sure that each Headline and it's article (matched my the array key) are saved the database as a row of data, and this is done for each headline and article pair.
I hope someone can follow all this help me.