Stuck on a form/wirebox problem?

Hey all,

This is my first attempt to write something since the class with Luis, BTW the class is excellent if you’re on the fence about going.


I have a simple form that is collecting name, email, phone number and comments from the user.

I have my model which has:

insert into contacts (name, email, phone, comments, contactdate) values ('#[](', '', '', '#rc.comments#', '#DateFormat(now(),'yyyy-mm-dd')# #TimeFormat(now(),'hh:mm:ss')#')

I have my handler:

property name=“contact” inject=“id”;

function index(event,rc,prc){

When I run this code I get an error that: Element NAME is undefined in RC.

I thought that the rc would persist and I should have access to the variables to proceed.

I know its something simple here that I am missing. I’m just glad that I retained most of this from class.

Thanks in advance.


The problem is not persistence, but passing it on. When you call anything in like a model the RC is not available and needs to be passed in.

You could do other ways, but I prefer to pass the entire thing through.

function index(event,rc,prc){

You could if you wanted too, inject the controller into the model and use the getCollection() to then get the RC, but I think passing it in is far better and easier to use and maintain.

Now if you look at your model, you will see that you have the required as arguments, these only exist for handlers and nothing more, so because you are not passing them in is the reason they do not exist.

Also It is not an issue, but you should set views at the end of the handler, now they are not processed until the function is finished, but from a readability point of view and flow of the function its makes better sense.

Hi Andrew,

Thanks for the reply.

I have changed everything to what you suggested but that also yields the same result.

function index(event,rc,prc){

God point about the views as well. Acually thinking about it, I don’t need the savecontact/index as I just want to to go to the general.index.

Did you change your model arguments?


No, I didn’t. I think I follow what you’re saying but I’m not sure how to do it.

I’m think it would be something like this:

Hopefully I am close.

No please re-read what I said and look at the arguments that you are saying that need to be passed in.

So unless you do

function index(event,rc,prc){
contact.PutContacts(rc = rc);

Then it will be passed in with the order you tell it. So if we go back to your model we can see that you want event as the first argument, then rc and the prc. Now the thing is you need to remove the event and prc as these are more than likely not being used or going to be used.

That is nothing to do with Coldbox and becomes a standard ColdFusion method for passing arguments into components. If you do the passing this way, the injection is not needed.

Does this make more sense now?

Thanks Andrew. It does make sense now and I was able to get it to work. The good thing is that I was thinking along these lines but just a little off. Thanks again for your help.

Your welcome, and just a side note that when learning Coldbox it is easy to get lost in the whole thing.

But glad your on your way now.