Yii Framework Forum: Ajax form sumbit - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Ajax form sumbit Rate Topic: -----

#1 User is offline   bitmatix 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 162
  • Joined: 23-March 09

Posted 14 August 2009 - 01:37 AM

I have a form with an ajaxSubmitButton, and I would like to know how I can achive, that on press "enter" the form would be submitted to the ajax request, and not the the given action?

By now, the ajax request is only fired by the ajaxSubmitButton and not by pressing the "enter" button (by pressing "enter" the form would be submitted to the given action, so I set it to "javascript: return false;").
0

#2 User is offline   jamesmoey 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 17-July 09

Posted 14 August 2009 - 02:09 AM

View Postbitmatix, on 14 August 2009 - 01:37 AM, said:

I have a form with an ajaxSubmitButton, and I would like to know how I can achive, that on press "enter" the form would be submitted to the ajax request, and not the the given action?

By now, the ajax request is only fired by the ajaxSubmitButton and not by pressing the "enter" button (by pressing "enter" the form would be submitted to the given action, so I set it to "javascript: return false;").


You just need to listen onsubmit event on the form itself, instead of onclick on the button.
e.g
<form ... onsubmit="runSomeJSFunction(); return false;">
...
</form>
0

#3 User is offline   auxbuss 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 164
  • Joined: 14-July 09
  • Location:Malvern, UK

Posted 14 August 2009 - 02:32 PM

Attach a .click event to the button. Something like:

<script type="text/javascript">
$(function() {
    $(".submit_button").click(function() {
        $.post(
            "../some/url,
etc.

0

#4 User is offline   Nemoden 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-March 09
  • Location:Vancouver, Canada

Posted 15 August 2009 - 11:33 AM

Why not use CHtml::ajaxButton()?
No brain - no pain.
My twitter :D
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 15 August 2009 - 03:47 PM

I see the ajax helpers in Yii only useful for simple cases. By using jquery "manually" you get the full power of AJAX and can do much like everything you want.

Edit: Sorry, a little OT :)
0

#6 User is offline   rudenich 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 30-April 10
  • Location:Ukraine-Kramatorsk

Posted 14 November 2010 - 02:52 PM

And how about case when i want have ajaxValidation of CActiveForm widget and ajax submit ?
0

#7 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 15 November 2010 - 04:41 AM

Just check validateOnSubmit.


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


Is that what do you need?
0

#8 User is offline   rudenich 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 30-April 10
  • Location:Ukraine-Kramatorsk

Posted 15 November 2010 - 04:48 AM

Yes, plus i want send already walidated form with ajax
0

#9 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 15 November 2010 - 05:02 AM

For this you can use the clientOptions:afterValidate.

I never tested, but according to documentation it looks like that you can trigger the ajax submission here and return false, in order to stop the usual submission.

Maybe something like that:

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'town-form',
        'enableAjaxValidation'=>true,
        'clientOptions'=> array(
             'validateOnSubmit'=>true,
		'afterValidate'=>'js:function(form, data, hasError) {if (!hasError){ '.CHtml::ajax([...]).'; return true;}}'

),
)); ?>

Something like that sould work.
0

#10 User is offline   radames_ 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 06-October 11
  • Location:São Paulo - Brazil

Posted 10 November 2011 - 09:03 AM

I have two forms and the form2 will get a id of form1 and with this id have a function that will bring and populate the form 2 with information of database ... how can I do it!
Radamés Galvao
PHP with Yii devel.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users