0

I have a Zend_Form

$form = new My_Form();
$uploadedData = $form->getValues();
Zend_Debug::dump($uploadedData, $form->name,true)

and when i dump the form values i get a string array

array(11) {
  ["event"] => string(2) "26"
  ["firstname"] => string(3) "sdf"
  ["surname"] => string(0) ""
  ["gender"] => string(1) "M"
  ["company"] => NULL
  ["dateOfBirth"] => string(10) "11-11-1977"
  ["address"] => string(6) "dfasdf"
  ["address2"] => string(4) "adfs"
  ["address3"] => string(4) "adfs"
  ["email"] => string(7) "[email protected]"
  ["mobile"] => string(0) ""
}

The form has the same number of fields as my DB table, the DB table def is

DROP TABLE IF EXISTS `registration`;
CREATE TABLE IF NOT EXISTS `registration` (
  `id` int(11) NOT NULL auto_increment,
  `event` int(11) NOT NULL,
  `firstname` varchar(50) NOT NULL,
  `surname` varchar(50) NOT NULL,
  `gender` varchar(5) NOT NULL,
  `dateofbirth` date NOT NULL,
  `address` varchar(50),
  `address2` varchar(50),
  `address3` varchar(50),
  `email` varchar(50) NOT NULL,
  `mobile` varchar(50),
  `company` int(11),
  `sector` int(11),
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

I'm getting a mapping error at the moment, since the DB event column can't take a string, and same with the 'dateofbirth' column

if($form->isValid($formData))
{
    $logger->info("valid form");
    $table = new Model_DbTable_Registration();
    ... // apply some custom mapping??
    $table->insert($uploadedData);
    ...    
}

I don't want to have to manually create a new array, and map each form field to the correct type by name - it seems like a pain. Is there a smarter way to do this mapping in Zend?

1
  • What kind of input are you using to set "event"? If the data is numeric, it should be numeric when you trace out the array. Commented Oct 26, 2009 at 14:32

1 Answer 1

1

That is why on the new ZF version is using the DataMapper Pattern for things like this, you abstract completely how to set, save and retrieve the data.

Your best bet is to create a new class and then interact with that class, and internally that class interact with your DbTable class.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there an example of this ? i cant find it :(.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.