Yii Framework Forum: how to save dynamic data from the View to data base - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

how to save dynamic data from the View to data base how to save dynamic data from the View to data base

#1 User is offline   callmesid 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 16

Posted 30 October 2017 - 07:11 AM

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
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,372
  • Joined: 16-February 11
  • Location:Japan

Posted 30 October 2017 - 07:33 AM

 callmesid, on 30 October 2017 - 07:11 AM, said:

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

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?

Quote

Now, how can i save this number into database.

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

#3 User is offline   callmesid 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 16

Posted 31 October 2017 - 08:01 AM

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
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,372
  • Joined: 16-February 11
  • Location:Japan

Posted 31 October 2017 - 09:17 AM

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

#5 User is offline   callmesid 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 16

Posted 01 November 2017 - 05:36 AM

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
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,372
  • Joined: 16-February 11
  • Location:Japan

Posted 01 November 2017 - 08:22 AM

What error do you get?
And what model are you using?
0

#7 User is offline   callmesid 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-November 16

Posted 01 November 2017 - 01:34 PM

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
0

#8 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,372
  • Joined: 16-February 11
  • Location:Japan

Posted 01 November 2017 - 06:11 PM

Please read the Guide.

Guide > Getting Started > Working with Forms
http://www.yiiframew...tart-forms.html
0

#9 User is offline   jkofsky 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 687
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 02 November 2017 - 02:32 PM

 callmesid, on 01 November 2017 - 05:36 AM, said:

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

Try giving the hiddenField the name of the 'attribute' that you want to save the value in.
Do, or do not. There is no 'try.' Jedi Master Yoda
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users