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 7868331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:57:57+00:00 2026-06-03T00:57:57+00:00

i am trying ajax based form submission in yii framework here is my view

  • 0

i am trying ajax based form submission in yii framework here is my view code

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'users-form',
    'enableAjaxValidation'=>true,
    'clientOptions'=>array('validateOnSubmit'=>true, 'validateOnType'=>false),
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <?php echo $form->labelEx($model,'user_username'); ?>
        <?php echo $form->textField($model,'user_username',array('size'=>45,'maxlength'=>45)); ?>
        <?php echo $form->error($model,'user_username'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'user_password'); ?>
        <?php echo $form->textField($model,'user_password',array('size'=>45,'maxlength'=>45)); ?>
        <?php echo $form->error($model,'user_password'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'user_role'); ?>
        <?php echo $form->dropDownList($model,'user_role', CHtml::listData($dropDownData, 'role_id', 'role_title')); ?>
        <?php echo $form->error($model,'user_role'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'user_company_id'); ?>
        <?php echo $form->textField($model,'user_company_id'); ?>
        <?php echo $form->error($model,'user_company_id'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::ajaxSubmitButton('Create User', CHtml::normalizeUrl(array(''), 
            array(
                'beforeSend'=>'function() {
                                    $(".createUser").attr("disabled","disabled");
                                }',
                'success'=>'function(data) {
                                alert(data);
                                if( data == "sent" ) {
                                    $(".ajaxMessage").text("User has been successfully created");
                                } else {
                                    $(".ajaxMessage").text("Oops! It looks there is some error in your form");
                                }
                                $(".createUser").removeAttr("disabled");
                            }'
            ),
            array('class'=>'createUser')
        )); ?>
    </div>

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

</div><!-- form -->
<div class="ajaxMessage"></div>

I want to grab the ajax response in variable. Here is the controller code

if(isset($_POST['Users']))
{
    if( Yii::app()->request->isAjaxRequest )
        echo 'ajax get';
    else
        echo 'ajax not get';
}

In firebug i have seen that response is generated correctly but it is not stored in my variable. The view code is created with the help of this link:
http://www.yiiframework.com/forum/index.php/topic/8219-solved-ajax-form-submission/

  • 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-03T00:57:59+00:00Added an answer on June 3, 2026 at 12:57 am

    The javascript data will be whatever you echo from controller. So if you want to check for data=="sent" in jquery’s success callback, do echo 'sent'; from the action.

    You have included the ajaxOptions inside the normalizeUrl function, change it to:

    <div class="row buttons">
        <?php echo CHtml::ajaxSubmitButton('Create User', CHtml::normalizeUrl(array('')), 
            array(
                'beforeSend'=>'function() {
                                    $(".createUser").attr("disabled","disabled");
                                }',
                'success'=>'function(data) {
                                alert(data);
                                if( data == "sent" ) {
                                    $(".ajaxMessage").text("User has been successfully created");
                                } else {
                                    $(".ajaxMessage").text("Oops! It looks there is some error in your form");
                                }
                                $(".createUser").removeAttr("disabled");
                            }'
            ),
            array('class'=>'createUser')
        ); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to learn class-based views, for a detail or list view is not
I have this JQuery code: jQuery(#form).click(function() { $(input[name='copyno']:checked).each(function() { checkboxData = copyno=+$(this).val(); id=$(this).val(); jQuery.ajax({
I'm trying to load portions of a form based on validation results. here is
I'm trying to determine the most secure method for an ajax based login form
I'm trying to modify the class of an element if an ajax call based
I was trying to use ckeditor with official jQuery Form Plugin for AJAX based
I am trying to AJAX some content into the #BlogContainer div and cannot seem
I'm trying to submit a form through AJAX instead of using the normal POST
I'm trying to create a AJAX based SQL query with Java EE and Servlets.
I'm trying to do a ajax check of username availability and submitting a form

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.