Yii Framework Forum: Ajaxbutton Problem - Yii Framework Forum

Jump to content

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

Ajaxbutton Problem Incorporate form values in data for post method Rate Topic: -----

#1 User is offline   Samrat Kar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 11-June 12
  • Location:Mumbai

Posted 12 October 2012 - 07:36 AM

Form is like that....

<form id="login-form" class="navbar-form pull-right">
	<input type="text" class="span2" placeholder="Username">
	<input type="password" class="span2" placeholder="Password">
	<?php 
	
	echo CHtml::ajaxButton('Login', 
				CController::createUrl('auth/ajaxLogin'), 
				array(
					'type'=>'POST',
					'data'=> ?????????,
					'dataType'=>'text',					
				),
				array(
					'class'=>'btn',
				)
				);	
	
	?>
</form>



I want to send username and password values to controller action via ajax post. How to send form data to controller?
0

#2 User is offline   antares 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 19-September 12

Posted 12 October 2012 - 07:42 AM

<form id="login-form" class="navbar-form pull-right">
        <input type="text" class="span2" placeholder="Username">
        <input type="password" class="span2" placeholder="Password">
        <?php 
        
        echo CHtml::ajaxButton('Login', 
                                CController::createUrl('auth/ajaxLogin'), 
                                array(
                                        'type'=>'POST',
                                        'data'=>'js:$("#login-form").serializeArray()',
                                        'dataType'=>'text',                                     
                                ),
                                array(
                                        'class'=>'btn',
                                )
                                );      
        
        ?>
</form>

0

#3 User is offline   Samrat Kar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 11-June 12
  • Location:Mumbai

Posted 12 October 2012 - 07:45 AM

Tried but not posting anything....
0

#4 User is offline   antares 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 19-September 12

Posted 12 October 2012 - 08:07 AM

Try this
<form id="login-form" class="navbar-form pull-right">
        <input id="login" type="text" class="span2" placeholder="Username">
        <input id="pass" type="password" class="span2" placeholder="Password">
        <?php 
        
        echo CHtml::ajaxButton('Login', 
                                CController::createUrl('auth/ajaxLogin'), 
                                array(
                                        'type'=>'POST',
                                        'data'=>array('login'=>'js:$("#login").val()','pass'=>'js:$("#pass").val()'),
                                        'dataType'=>'text',                                     
                                ),
                                array(
                                        'class'=>'btn',
                                )
                                );      
        
        ?>
</form>

0

#5 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 12 October 2012 - 09:27 AM

Dear Friend

Would you please try the following?

1.There is no name attribute for the form fields.Then it is impossible to get serialized.

2.use CHtml::ajaxSubmitButton instead of ajaxButton.

3.Try to include complete function to test the AJAX request in firebug console.(optional)

<form id="login-form" class="navbar-form pull-right">
        <input type="text" class="span2" placeholder="Username" name="name">
        <input type="password" class="span2" placeholder="Password" name="pass">
        <?php 
        
        echo CHtml::ajaxSubmitButton('Login', 
                                CController::createUrl('auth/ajaxLogin'), 
                                array(
                                        'type'=>'POST',
                                        'data'=>'js:$("#login-form").serialize()',
                                        'complete'=>'js:function(i,j) {console.log(i);}'                                     
                                ),
                                array(
                                        'class'=>'btn',
                                )
                                );      
        
        ?>
</form>




Regards.
0

#6 User is offline   Samrat Kar 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 11-June 12
  • Location:Mumbai

Posted 15 October 2012 - 01:58 AM

Thank you seenivasan and antares
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