Help dealing with data dependency between two registration forms

I have a tricky issue here with a registration of both a user and his/her pet. Both the user and the pet are treated as separate entities and both require separate registration forms. However, the user’s pet has to be linked to the user via a foreign key in the database. The process is basically that when a new user joins the site, firstly they register their pet, then they register themselves. The reason for this order is to check their pet’s eligibility for the site (there are some criteria to be met) first, instead of getting the user to sign up only to then find out their pet is ineligible. It is this ordering of the form submissions which is causing me a bit of a headache, as follows…

The site is being developed with an MVC framework, and the User registration process is managed via a method in a User_form controller, while the pet registration process is managed via a method in the Pet_form controller.

The pet registration form happens first, and the pet data can be saved without the owner_id at this stage, with the user id possibly being added (e.g by retrieving pet’s id from session) following user registration. However, doing it this way could potentially result in redundant data, where pet records would be created in the database, but if the user doesn’t actually register themselves too, then the pets will be ownerless records in the DB.

Other option is to serialize the new pet’s data at the pet registration stage, don’t save it to the DB until the user fills out their registration form. Once the user is created, i can pass serialised data AND the owner_id to a method in the Pet Model which can update the DB. However, I also need to set the newly created $pet to $this->pet which I then access for a sequence of other related forms. Should I just set the session variable in the model method? Then in the Pet controller constructor, do a check for pet stored in session, if yes, assign to $this->pet…

If this makes any sense to anybody and you have some advice, i’d be grateful to hear it!

I’d say the ownerless records may be better, depending on: does the user have to register immediately after their pet?

If not, e.g. Is there a moderation process? How long between pet registration and user registration? If it’s not likely to be the same browser session, you’ll almost certainly want them in the database. How do you recognise the user when they come back?

If it is always going to be in the same browser session, where the eligibility checks are done by the site, the session will work better.

You may still want to log to the database that a pet has been registered. Wouldn’t it be useful to know in the future how many gave up half way through the process? This sort of information can help you work out, for example, if your form is too long and people are getting bored and giving up.

I would opt for your second method. Save the pet data in the session and insert it with the user upon registration. That seems like the most simple and straight-forward manor to solve your problem.

Thanks @oddz and @TomB! At the moment, I’m leaning more towards the second option myself here.

TomB, the user registration follows immediately after the pet registration. Both of these are the first two sections of a longer set of forms, however, these first two forms are essentially responsible for creating db records for both the pet and its owner.

I can’t see many situations where someone completes the pet registration (only 5 questions), then doesn’t fill out the next stage to register themselves (again, only 5 questions). In situations where this does happen, I think it will be ok to expect people to start from the pet registration stage again, as the owner themselves will not be able to login to a user account to manage their pet data until they have registered themselves. I’m thinking it could be tricky managing the link up between ownerless pets and new user accounts…

For new and returning owners, i have a base controller which all other controllers (mainly form related) extend. In the constructor of the base controller, I have the following code to try and set the pet and user data correctly for the session. When a new pet and user are registered, I create a new session for them which allows them to be assigned to $this->pet and $this->user. If it is a returning user then this works ok, as there will be a session following their login - when they select a pet to manage (they may have more than one), I plan just to use the id of the pet to generate a session for that pet.

Then all form processing throughout the site references $this->user and $this->pet. Does this make sense or could it be improved? One thing I’m aware of is that as most controllers extend the Website Controller, then I will constantly be performing the session check and reassigning the session data to $this->user and $this->pet.

Thanks for your help here, i’m trying to keep this as sensible and clean as possible!

class Website_Controller extends Template_Controller {
		
		protected $user;
		protected $pet;
		
		public function __construct()
		{
				parent::__construct();
				
                if (Auth::instance()->logged_in())
                {
				     //retrieve user as object 
				     $this->user = Session::instance()->get('auth_user');
                }				
				//if pet data exists in session, assign it
				if (Session::instance()->get('pet'))
				{
					$this->pet = Session::instance()->get('pet');
				}
		}
}