0

I am writing small invite a friend extension on typo3 6.1.3. Here what I need is, I can send invitation to friends by adding there email address in text field. After sending by pressing submit button, that person will receive a message and that email address is going to save in database.

So my database looks like this

CREATE TABLE tx_myext_domain_model_mytable(
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
invitemail varchar(255) DEFAULT '' NOT NULL
)

My create action looks like this

public function createAction(\TYPO3\Myext\Domain\Model\Myext $newInvitefriend) {
$this->invitefriendRepository->add($newInvitefriend);

/*
* Email Part
*/

$emailTo = $newInvitefriend->getInvitemail();
//send mail

}

In create from what I need is, multiple invitemail fields (arrray)

<input type="text" name="tx_myext_invitefriend[newInvitefriend][invitemail][]"><br />
<input type="text" name="tx_myext_invitefriend[newInvitefriend][invitemail][]"><br />

and I can add new field as many as I want. so by submitting this form separate records for each email address should be created in backend.

How can we achieve this ? Any help ? Thank you

1 Answers1

0

You cannot do this with the out-of-the-box features.

But in your createAction, you can get the request arguments:

$newInviteFriends = $this->request->getArguments('newInvitefriend');

and then loop through the inviteFriends

foreach ($newInviteFriends as $newInviteFriend) {
   $newInviteFriend = $this->objectManager->create('\Vendor\Extension\Domain\Model\Modelname');
   $newInviteFriend->setInvitemail($newInviteFriend['invitemail']);
   $this->sendInviteMail($newInviteFriend['invitemail']
}

Don't forget to sanitize the input.

lorenz
  • 4,538
  • 1
  • 27
  • 45