how to save dynamic data from the View to data base

Hi Experts,

I am bit new to the Yii framework. Can somebody help me on the below issue?

In view file, i am running one function which will generate random number, which will create new number on page refresh.

Now, how can i save this number into database.

In normal user textinput it is working fine. But instead of textinput, I want to put this auto generated number and save it to database.

Any ideas?

Thanks in advance.

Sid

What does this number do? What do you want to do with this random number?

And is the view a form, or a normal page without a form?

Why do you want to save it? You probably want to read it from db later, but what for?

Application is creation of number combination, which will be generated and saved for future view.

Like in gambling. But i want to save the numbers in DB.

Regards,

Sid

Use a hidden field instead of a text input, and set the generated random value to it.

Thanks for your reply.

I have put "hiddenfield" options. It is showing the random no as expected. For testing purpose i have put one submit button. but when i am submitting these, it is showing validation error.

can you guide me please.

Regards,

Sid

What error do you get?

And what model are you using?

Model is similar to the user registration mkdel in advance template. Error: field1 and field2 can’t be blank. These two fields need the data from the random no input in the view file.

Any suggestion please.

Regards,

Sid

Please read the Guide.

Guide > Getting Started > Working with Forms

http://www.yiiframework.com/doc-2.0/guide-start-forms.html

Try giving the hiddenField the name of the ‘attribute’ that you want to save the value in.