Yii Framework Forum: In Form, Display More Textfield Input If The First One Is Filled - Yii Framework Forum

Jump to content

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

In Form, Display More Textfield Input If The First One Is Filled Rate Topic: -----

#1 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 21 November 2012 - 05:07 AM

Hello,

I would like to be able to give the possibility to a user to enter several data for one field. To do that, I would like simply display one more textfield input every time this above is filled.

Example : A user can enter all the color he would like to have for his car. In form there is the line "color" with the input textfield attached. If he fills the input textfield, a second one appears just below. If the second one is filled a third one appears below etc...

Do you have an idea of how I could reach that ?

thanks
0

#2 User is offline   yiiplayboy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 03-May 12

Posted 21 November 2012 - 05:18 AM

View PostZugluk, on 21 November 2012 - 05:07 AM, said:

Hello,

I would like to be able to give the possibility to a user to enter several data for one field. To do that, I would like simply display one more textfield input every time this above is filled.

Example : A user can enter all the color he would like to have for his car. In form there is the line "color" with the input textfield attached. If he fills the input textfield, a second one appears just below. If the second one is filled a third one appears below etc...

Do you have an idea of how I could reach that ?

thanks



What you want is a client side script i.e. javascript or jquery. I would recommend adding a button to raise an event which creates the textfield below your initial textfield....a simple search on google would get you enough options of doing this...
check this link http://stackoverflow...lly-with-jquery
0

#3 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,601
  • Joined: 04-March 10
  • Location:UK

Posted 21 November 2012 - 05:25 AM

You'll need to use jQuery to create new elements on the fly and receive them in PHP as an array. For instance, if you had the following input:

<input type="text" name="color[]" value="" />


you could duplicate that as many times as needed. PHP will receive an array when the form is submitted.
0

#4 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 22 November 2012 - 08:48 AM

Thanks for all of your response, well for moment I adopted another strategy. I ask the user to write his colors with a comma separating all of them then I collect the string, delete all spaces, and 'explode' it. It makes the work, I will lean on something more "fancy" later =P
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