Yii Framework Forum: How To Insert Append <Div> Data Into Database - Yii Framework Forum

Jump to content

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

How To Insert Append <Div> Data Into Database Rate Topic: -----

#1 User is offline   beginner123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 03-March 14

Posted 27 March 2014 - 01:43 AM

Hi all, I am doing append data for <div> by using javascript now. But, I am struggling on how to insert data for the fields that I have appended? Can anyone guide me on this?

I have a button to click and once I click, the content of the <div> will be appended. How am I going to insert the data into database that are filled into the appended field? Thanks in advance~

<script>
	var _counter = 0;
    function Add() {
    _counter++;
    var oClone = document.getElementById("template").cloneNode(true);
    oClone.id += (_counter + "");
    document.getElementById("add").appendChild(oClone);
    }</script>

	<div id="add">
	<div id="template">
	<fieldset style="margin-left:10px; margin-right:10px; background-color:#FFFFE0">
	<div style="margin-left:85px">
    <?php echo $form->labelEx($model,'day'); ?>
	<div style="margin-left:95px; margin-top:-30px">
	<?php echo $form->dropDownList($model,'day', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?>
    </div></div></br>

	<div style="margin-left:48px">
    <?php echo $form->labelEx($model,'start'); ?>
	<div style="margin-left:130px; margin-top:-30px">
	<?php 
    $this->widget('ext.timepicker.timepicker', array(
    'model'=>$model,
    'name'=>'start',
    ));
    ?> </div></div></br>

	<div style="margin-left:48px">
    <?php echo $form->labelEx($model,'end'); ?>
	<div style="margin-left:130px; margin-top:-30px">
	<?php 
    $this->widget('ext.timepicker.timepicker', array(
    'model'=>$model,
    'name'=>'end',
    ));
    ?> </div></div>

    </div></div>   
	
	<div style="margin-left:20px">
	<?php echo CHtml::button('Add More Details', array('onclick' => 'Add()')); ?>
	</div>
    </div></div>

0

#2 User is offline   georaldc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 08-July 11

Posted 27 March 2014 - 09:55 AM

Not sure I understand what you want to do but you could probably define an extra attribute to hold your data then append it to your loaded model in the beforeValidate method
0

#3 User is offline   beginner123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 03-March 14

Posted 27 March 2014 - 10:43 AM

View Postgeoraldc, on 27 March 2014 - 09:55 AM, said:

Not sure I understand what you want to do but you could probably define an extra attribute to hold your data then append it to your loaded model in the beforeValidate method

Hi, georaldc. Thanks for the reply. Let me explain to u one more time. Currently, I am having 3 fields to fill out. I wish to append these 3 fields again as I need to fill out more details. But, I do not know how to save that extra 3 fields of data into database since the 3 fields of data are appended. Maybe the image in the attachment can help you to understand my problem clearly.

Attached File  Untitled.png (11.32K)
Number of downloads: 3

Here's my code
<script>
	var _counter = 0;
    function Add() {
    _counter++;
    var oClone = document.getElementById("template").cloneNode(true);
    oClone.id += (_counter + "");
    document.getElementById("add").appendChild(oClone);
    }</script>

	<div id="add">                     //the 3 fields are appended once I clicked the button
	<div id="template">
	<fieldset style="margin-left:10px; margin-right:10px; background-color:#FFFFE0">
	<div style="margin-left:85px">
    <?php echo $form->labelEx($model,'day'); ?>
	<div style="margin-left:95px; margin-top:-30px">
	<?php echo $form->dropDownList($model,'day', CHtml::listData(CourseType::model()->findAll(), 'day', 'day'), array('empty'=>'Please Select Day')); ?>
    </div></div></br>

	<div style="margin-left:48px">
    <?php echo $form->labelEx($model,'start'); ?>
	<div style="margin-left:130px; margin-top:-30px">
	<?php 
    $this->widget('ext.timepicker.timepicker', array(
    'model'=>$model,
    'name'=>'start',
    ));
    ?> </div></div></br>

	<div style="margin-left:48px">
    <?php echo $form->labelEx($model,'end'); ?>
	<div style="margin-left:130px; margin-top:-30px">
	<?php 
    $this->widget('ext.timepicker.timepicker', array(
    'model'=>$model,
    'name'=>'end',
    ));
    ?> </div></div>

    </div></div>   
	
	<div style="margin-left:20px">
	<?php echo CHtml::button('Add More Details', array('onclick' => 'Add()')); ?>
	</div>
    </div></div>

0

#4 User is offline   georaldc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 08-July 11

Posted 27 March 2014 - 03:17 PM

Looks like you want to insert tabular data. The Yii docs has a quick article on that:

http://www.yiiframew...1/en/form.table
0

#5 User is offline   beginner123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 03-March 14

Posted 28 March 2014 - 03:07 AM

View Postgeoraldc, on 27 March 2014 - 03:17 PM, said:

Looks like you want to insert tabular data. The Yii docs has a quick article on that:

http://www.yiiframew...1/en/form.table


Ya, but i am wondering how to insert the data from appended field into database?? This is because the appended field is the extra field from the database. If I create the extra fields in my database, how to make sure that the appended field is the extra field in the database? Do you get what I mean?
Thank you.
0

#6 User is offline   georaldc 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 08-July 11

Posted 28 March 2014 - 11:18 AM

View Postbeginner123, on 28 March 2014 - 03:07 AM, said:

Ya, but i am wondering how to insert the data from appended field into database?? This is because the appended field is the extra field from the database. If I create the extra fields in my database, how to make sure that the appended field is the extra field in the database? Do you get what I mean?
Thank you.

How does your database table or the model for this look like?
0

#7 User is offline   beginner123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 03-March 14

Posted 29 March 2014 - 12:27 AM

View Postgeoraldc, on 28 March 2014 - 11:18 AM, said:

How does your database table or the model for this look like?

My database look like this:
id | code | name | type | credit_hour | prerequisite | session | total_student | day | start | end |

The day, start and end fields will be appended if the user wish to add more details. So, I was wondering how to insert the appended of day,start and end fields into database? The user may append more than one time. Can you guide me? Thanks~
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