Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:22:39+00:00 2026-06-05T17:22:39+00:00

confusion between form and chtml i used to form to write form ans submit

  • 0

confusion between form and chtml

i used to form to write form ans submit to database working fine, but for some particular places, according to google search used CHTML instead of form. but when i submitted that form to database

CHTML textfield value is not submitting to database

here goes my code

_Form.php

 <script language="javascript">

function firstlang(flang,slang,tlang,math,scien,soci)
{

var sflang=parseInt(flang)+parseInt(slang)+parseInt(tlang)+parseInt(math)+parseInt(scien)+parseInt(soci);
document.getElementById('totalmarks').value=sflang;
if(sflang>=300 && sflang<400)
{
var flang='C';
document.getElementById('grade').value=flang;
}
else if(sflang>=400 && sflang<500)
{
var flang='B';
document.getElementById('grade').value=flang;   
}
else if(sflang>=550 && sflang<=600)
{
var flang='A';
document.getElementById('grade').value=flang;   
}
}

</script>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'marks-form',
    'enableAjaxValidation'=>true,
     'enableClientValidation'=>true,
      'focus'=>array($model,'class'),
)); ?>
    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>
<table width="200" border="1">
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'class'); ?></span></td>
    <td><span class="row">

   <?php echo CHtml::dropDownList('class','',CHtml::listData(class1::model()->findAll(),'class','class'),array('empty'=>'Choose one',

'ajax' => array(

'type'=>'POST', //request type
'url'=>CController::createUrl('Marks/dynamicstates'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update'=>'#studentid', //selector to update
//'data'=>'js:javascript statement'
//leave out the data key to pass all form values through
)));

//empty since it will be filled by the other dropdown
?></span></td>
    <td><span class="row"><?php echo $form->error($model,'class'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'studentid'); ?></span></td>
    <td><span class="row"><?php echo CHtml::dropdownlist('studentid','',array()); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'studentid'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'examtype'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'examtype',array('size'=>30,'maxlength'=>30)); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'examtype'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'firsttlanguage'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'firsttlanguage',array('id'=>'firsttlanguage','value'=>'0','onkeyup'=>'firstlang(this.value,secondlanguage.value,thirdlanguage.value,mathematics.value,science.value,social.value)')); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'firsttlanguage'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'secondlanguage'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'secondlanguage',array('id'=>'secondlanguage','value'=>'0','onkeyup'=>'firstlang(this.value,firsttlanguage.value,thirdlanguage.value,mathematics.value,science.value,social.value)')); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'secondlanguage'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'thirdlanguage'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'thirdlanguage',array('id'=>'thirdlanguage','value'=>'0','onkeyup'=>'firstlang(this.value,firsttlanguage.value,secondlanguage.value,mathematics.value,science.value,social.value)')); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'thirdlanguage'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'mathematics'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'mathematics',array('id'=>'mathematics','value'=>'0','onkeyup'=>'firstlang(this.value,firsttlanguage.value,secondlanguage.value,thirdlanguage.value,science.value,social.value)')); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'mathematics'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'science'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'science',array('id'=>'science','value'=>'0','onkeyup'=>'firstlang(this.value,firsttlanguage.value,secondlanguage.value,thirdlanguage.value,mathematics.value,social.value)')); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'science'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'social'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'social',array('id'=>'social','value'=>'0','onkeyup'=>'firstlang(this.value,firsttlanguage.value,secondlanguage.value,thirdlanguage.value,mathematics.value,science.value)')); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'social'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'totalmarks'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'totalmarks',array('id'=>'totalmarks','size'=>5,'maxlength'=>5)); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'totalmarks'); ?></span></td>
  </tr>
  <tr>
    <td><span class="row"><?php echo $form->labelEx($model,'grade'); ?></span></td>
    <td><span class="row"><?php echo $form->textField($model,'grade',array('id'=>'grade','size'=>5,'maxlength'=>5)); ?></span></td>
    <td><span class="row"><?php echo $form->error($model,'grade'); ?></span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><span class="row buttons"><?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?></span></td>
    <td>&nbsp;</td>
  </tr>
</table>





<?php $this->endWidget(); ?>

</div><!-- form -->

MarksController.php

<?php

class MarksController extends Controller
{
    /**
     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
     * using two-column layout. See 'protected/views/layouts/column2.php'.
     */
    public $layout='//layouts/column2';

    /**
     * @return array action filters
     */
    public function filters()
    {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules()
    {
        return array(
            array('allow',  // allow all users to perform 'index' and 'view' actions
                'actions'=>array('index','view'),
                'users'=>array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('create','update'),
                'users'=>array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions'=>array('admin','delete'),
                'users'=>array('admin'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions'=>array('admin','dynamicstates'),
                'users'=>array('admin'),
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

    /**
     * Displays a particular model.
     * @param integer $id the ID of the model to be displayed
     */
    public function actionView($id)
    {
        $this->render('view',array(
            'model'=>$this->loadModel($id),
        ));
    }

    /**
     * Creates a new model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     */
    public function actionCreate()
    {
        $model=new Marks;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['Marks']))
        {
            $model->attributes=$_POST['Marks'];
            if($model->save())
                $this->redirect(array('view','id'=>$model->id));
        }

        $this->render('create',array(
            'model'=>$model,
        ));
    }

    /**
     * Updates a particular model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id the ID of the model to be updated
     */
    public function actionUpdate($id)
    {
        $model=$this->loadModel($id);

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['Marks']))
        {
            $model->attributes=$_POST['Marks'];
            if($model->save())
                $this->redirect(array('view','id'=>$model->id));
        }

        $this->render('update',array(
            'model'=>$model,
        ));
    }

    /**
     * Deletes a particular model.
     * If deletion is successful, the browser will be redirected to the 'admin' page.
     * @param integer $id the ID of the model to be deleted
     */
    public function actionDelete($id)
    {
        if(Yii::app()->request->isPostRequest)
        {
            // we only allow deletion via POST request
            $this->loadModel($id)->delete();

            // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
            if(!isset($_GET['ajax']))
                $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
        }
        else
            throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
    }

    /**
     * Lists all models.
     */
    public function actionIndex()
    {
        $dataProvider=new CActiveDataProvider('Marks');
        $this->render('index',array(
            'dataProvider'=>$dataProvider,
        ));
    }

    /**
     * Manages all models.
     */
    public function actionAdmin()
    {
        $model=new Marks('search');
        $model->unsetAttributes();  // clear any default values
        if(isset($_GET['Marks']))
            $model->attributes=$_GET['Marks'];

        $this->render('admin',array(
            'model'=>$model,
        ));
    }

    /**
     * Returns the data model based on the primary key given in the GET variable.
     * If the data model is not found, an HTTP exception will be raised.
     * @param integer the ID of the model to be loaded
     */
    public function loadModel($id)
    {
        $model=Marks::model()->findByPk($id);
        if($model===null)
            throw new CHttpException(404,'The requested page does not exist.');
        return $model;
    }

    /**
     * Performs the AJAX validation.
     * @param CModel the model to be validated
     */
    protected function performAjaxValidation($model)
    {
        if(isset($_POST['ajax']) && $_POST['ajax']==='marks-form')
        {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }
    }
public function actiondynamicstates()
{

      // $model1=new Examresults;
        /*$exam_type=(int)$_POST['exam_type'];


        if ($exam_type==0)
                $data=array(0=>'States:');
        else if ($exam_type==1)
                $data=array(1=>'Alaska', 2=>'California');    
        else if ($exam_type==2)
                $data=array(1=>'Orleans', 2=>'Bordeaux');
        else if ($exam_type==3)
                $data=array(1=>'Hokkaido', 2=>'Okinawa');*/
//$schoolfee = feesettings::model()->find("feetype='schoolfee' and class='".$_REQUEST['class']."'");

 $data=admission::model()->findAll('class=:class',
                  array(':class'=>$_POST['class']));


   $data=CHtml::listData($data,'studentid','studentfname');

        foreach($data as $value=>$name)
                echo CHtml::tag('option', array('value'=>$value), CHtml::encode($name), true);

}

}

Marks.php

<?php

/**
 * This is the model class for table "marks".
 *
 * The followings are the available columns in table 'marks':
 * @property integer $id
 * @property string $class
 * @property string $studentid
 * @property string $examtype
 * @property integer $firsttlanguage
 * @property integer $secondlanguage
 * @property integer $thirdlanguage
 * @property integer $mathematics
 * @property integer $science
 * @property integer $social
 * @property integer $totalmarks
 * @property string $grade
 */
class Marks extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Marks the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'marks';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('class, studentid', 'required'),
            array('firsttlanguage, secondlanguage, thirdlanguage, mathematics, science, social, totalmarks', 'numerical', 'integerOnly'=>true),
            array('class, studentid, examtype', 'length', 'max'=>30),
            array('grade', 'length', 'max'=>5),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, class, studentid, examtype, firsttlanguage, secondlanguage, thirdlanguage, mathematics, science, social, totalmarks, grade', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'class' => 'Class',
            'studentid' => 'Studentid',
            'examtype' => 'Examtype',
            'firsttlanguage' => 'Firsttlanguage',
            'secondlanguage' => 'Secondlanguage',
            'thirdlanguage' => 'Thirdlanguage',
            'mathematics' => 'Mathematics',
            'science' => 'Science',
            'social' => 'Social',
            'totalmarks' => 'Totalmarks',
            'grade' => 'Grade',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('class',$this->class,true);
        $criteria->compare('studentid',$this->studentid,true);
        $criteria->compare('examtype',$this->examtype,true);
        $criteria->compare('firsttlanguage',$this->firsttlanguage);
        $criteria->compare('secondlanguage',$this->secondlanguage);
        $criteria->compare('thirdlanguage',$this->thirdlanguage);
        $criteria->compare('mathematics',$this->mathematics);
        $criteria->compare('science',$this->science);
        $criteria->compare('social',$this->social);
        $criteria->compare('totalmarks',$this->totalmarks);
        $criteria->compare('grade',$this->grade,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:22:40+00:00Added an answer on June 5, 2026 at 5:22 pm

    Have a look here Creating Form. Since Yii 1.1.1 there is a widget called CActiveForm
    so when you use this widget you create the form inputs with $form->textField($model,'username')instead of using CHtml::activeTextField($model,'username')but both work in the same way.

    So if that field is not being saved in the database it’s probably because you haven’t added it to the rules of your model.

    public function rules() {
        return array(
            array('username', 'safe'),
        );
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to C and I experience some confusion between the declaration and
I have a confusion between two B keywords. The official B reference manual uses
I am experiencing some confusion on the Kernel#sprintf method in Ruby. Ruby 1.9 handles
I have a lot of confusion on understanding the difference between a far pointer
I'm trying to form an unholy alliance between Coldfusion MX 7, Tomcat, and OS
I see a lot of confusion between hashes and encryption algorithms and I would
I ran into a bug in Firefox involving some out-of-sync information on my form
I'm working on a windows forms application (.NET 4.0). My form contains a 'Fast
I'm working with existing code that has an object store in the form of
I have some confusion related to the .NET platform build options in Visual Studio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.