Help With Ajaxbutton

I have a textarea where users submit URLs to our database. The problem is that my scripts are timing out when a user submits over 1000 URLs. So I need to use some javascript and split up the data before it gets sent to the php script. I have a very basic model working outside of Yii but need some help writing the code in Yii. Any help would be appriciated.

Here’s the code outside of yii






<script type="text/javascript" src="jquery.min.js"></script>

<form action="form.php" method="post" id="target">

    <textarea name="urls" id="urls" style="width:300px;height:200px">



    <input type="submit">


<script type="text/javascript">

    $('#target').submit(function() {

        var urls = $('#urls').val().trim().split("\n");

        var splitArray = chunk(urls,10);

        for (var ary in splitArray){



        return false;


    function chunk (arr, len) {

        var chunks = [],

            i = 0,

            n = arr.length;

        while (i < n) {

            chunks.push(arr.slice(i, i += len));


        return chunks;






My model is just a basic gii generated model - nothing really special there

Here’s my controller:

public function actionAdd()



        $model=new Urls;



            $urls = explode("\n", $model->urlList);

            $success = 0;

            $error = 0;

            foreach($urls as $url)

                if(!empty($url)): // don't save empty lines

                    $newUrl=new Urls; //That's what you want: an extra model for each name

                    $newUrl->url = trim($url);

                    $newUrl->statusID = 1;

                    $newUrl->date = date("Y-m-d");

                    $newUrl->posts = 0;

                    $newUrl->clientID = Yii::app()->user->getId();









            if($success > 0)

                Yii::app()->user->setFlash('success', $success . ' URLs added.');

            if($error > 0)

                Yii::app()->user->setFlash('error', $error . ' duplicate or malformed URLs were not added.');











And my view (using yii-bootstrap)


/* @var $this UrlsController */

/* @var $model Urls */


<div class="span12" style="margin: 50px 0 10px"><?php



<h1 class="title">Add Urls</h1>

<?php $this->widget('bootstrap.widgets.TbAlert', array(

    'block'=>true, // display a larger alert block?

    'fade'=>true, // use transitions?

    'closeText'=>'&times;', // close link text - if set to false, no close link is displayed

    'alerts'=>array( // configurations per alert type

        'success'=>array('block'=>true, 'fade'=>true, 'closeText'=>'&times;'), // success, info, warning, error or danger


)); ?>

<div class="form">

    <?php $form=$this->beginWidget('CActiveForm', array(




            'onsubmit'=>'return false',


    )); ?>

    <p class="note">Add 1 URL per line</p>

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

    <div class="row" style="margin-left:0">

        <?php echo $form->labelEx($model,'urlList'); ?>

        <?php echo $form->textArea($model,'urlList',array('style' => 'width:90%;height:500px')); ?>

        <?php echo $form->error($model,'urlList'); ?>


    <div class="row buttons" style="margin-left:0">

        <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Submit')); ?>

        <?php //echo CHtml::submitButton('Save'); ?>


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

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

This currently returns an alert for the number of URLs submitted - will want to use some form of real time feedback between calls - probably a progress bar from bootstrap.

Thanks for your help