Forums

Do not save if....

ianmaciel 27 Feb, 2013
There is any way to stop saving into DB if I have some special condition?

I have a form where users fill some fields. If the user is register I am saving this to their account (it is already working) but if the user is a guest I don'y want to save it.

The biggest problem is: I use this form to save the data into user's account and than when users login again I retrieve these data and show the form already filled. If the system saves all the forms every guest would see a form already filled by the last guest user.

I have any idea how to avoid saving.

I have this working now with some php test before showing html:
if ( ($form->data['user_id']==0) ) {
  $form->data['cf_id'] = "1";
  $form->data['fild1'] = "";
  $form->data['fild2'] = "";
}


So the form appear blank without any information but I don't think this is the best way to do it.
It still saving to user "0" but I discart this information on loading.

One more information: I'm avoiding to create another form to unregistered users to keep the same URL-friendly. So does not matter if the user is registered or not the URL will be the same.

Thanks,
Ian Maciel
GreyHead 27 Feb, 2013
Hi Ian,

Please see this FAQ. If you use the Event Switcher [GH] you can check if the user is logged in and only add the DB Save action to that event.

Bob
This topic is locked and no more replies can be posted.