jcastillotx - 11 months ago

Ok so I am using a multiform builder for two streams (donor and donations). I have everything working but I need to be able to check if donor already exists then to skip the donor creation and pull data from the existing donor record to synch with new donation. Looking for how I do this. I tried formhandler and using a callback in the main controller

ryanthompson - 11 months ago

If you set the entry ID on the form it will do this for you automatically. The controller should provide that to the form.

jcastillotx - 11 months ago

Ryan not understanding what you mean. So I did the hard way and grabbed last donor created that has the same email multiple times in DB. I delete the latest and then match the id of the existing to the donation. How can you do it easier with what you are saying?

// Get Last Input $last = $donorModel->getLast( $multiple->getFormValue( 'donor_donor_email' ) );

// Delete the Last Input $donorModel->deleteDonor( $last->id );

ryanthompson - 10 months ago

Your donors should be unique per email right? Getting the last by email seems hacky.. what I was saying is instead of looking for existing entries in you handler - you should do that before your form is built and set the value on the form like $builder->setEntry($donor->findByEmail($email)); That way the form builder knows it exists - that's what your editing. OR if it returns null it'll be created.

If you need to set that object for a relation in subsequent child forms like before saving setting the donor_id on a related model do something like this: https://github.com/anomalylabs/navigation-module/blob/2.2/src/Link/Form/LinkFormBuilder.php#L70

jcastillotx - 10 months ago

Where would I put the following $builder->setEntry($donor->findByEmail($email)); --> Controller, FormBuilder, FormHandler?

jcastillotx - 10 months ago

Never mind figured it out. Thanks for the update.