Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Ajax Trigger In Yii

$
0
0
Hello, i need help form pro's.
How do i make form that when i click on Submit, it makes Ajax request instead of submitting/refreshing page?
This is what i have currently, but it is not working:
The form HTML code:
	<div class="row">
		<label for="Book_author">Author</label>        <div class="ajax-form">
	<div class="row">
		<label for="Person_fname">First Name</label>		<input size="60" maxlength="64" name="Person[fname]" id="Person_fname" type="text" />		<label for="Person_lname">Last Name</label>		<input size="60" maxlength="64" name="Person[lname]" id="Person_lname" type="text" />	</div>
</div>&lt!-- form -->
        <div class="row buttons">
            <input class="add" type="button" obj="Person" url="/cbdb/index.php?r=book/createAuthor&id=7&ajax=1" value="Add" />
        </div>


And here is book/createAuthor function code:
    public function actionCreateAuthor($id){
        // request must be made via ajax
        if(isset($_GET['ajax']) && isset($_GET['person'])){
            $model=  $this->loadModel($id);
            $author=new Person();
            $author->attributes=$_GET['Person'];
            if(($author->fname!=null) && ($author->lname!=null)){
                $model->addAuthor($author);
                $this->renderPartial('_li',array('model'=>$model, 'author'=>$author),false,true);
            }
        }else{
            throw new CHttpException(400,'Invalid request.');
        }
    }

Unfortunately when i click on Add button nothing appends.
I am following "Yii Rapid Application Development Hotshot [eBook].pdf" book, chapter 2 (page ~69)

I wouldn't say i am complete beginner in PHP and Yii, but when it comes to Ajax i am beginner.
Any help will be highly appreciated.

Viewing all articles
Browse latest Browse all 18717

Trending Articles