I have created text fields

<fieldset class="step">
        <label for="Certifications">Certifications:</label><br>
        <label style="margin-left: -125px !important;">
            <div id='test_certify' style="display:table;">
            <table id="mytable" width="5%">
              <td align='middle'>Certification Name</td>
              <td>Pass Out Year</td>
            <? $tr_id=1; ?>
            <tr id=<?echo $tr_id; ?> >
                        echo CHtml::activeTextField(EmpCertificates::model(),'Name',array('id'=>'C_name-'.$tr_id,));
                <td> <input for date> </td>
                <img width="15" height="15" id="add" alt="Add More" src="/employee_skill_set_priti_2/images/more.png">


and cloned it using below code.

                    var last_tr_id=parseInt($('#mytable tr:last').attr('id'));
                    last_tr_id=parseInt(last_tr_id + 1);
                    var $clone = $('#mytable tbody>tr:last').clone(true);
                        id: parseInt(last_tr_id),

                                var res = ($(this).attr("id")).split("-");
                                var new_id=res[0] + "-"+last_tr_id;
                                    id: new_id,
                                    name: new_id,
            $($clone).insertAfter("#mytable tbody>tr:last");

When i submit form thrn it gives mew data like:

[C_name-1] => certification1
    [last_used_in-2] => 2012
   [C_name-2] => certification2
    [last_used_in-2] => 2012
    [C_name-3] => certification3
    [last_used_in-3] => 2012

Can can I make array of these values?
like i get

1=> //certification 1 values
                C_name-1 => certification1
                last_used-1 => 2012
                C_name-2 => certification2
                last_used-2 => 2012
2=> ....

how to form such array?
or how to send it while submitting?

Recommended Answers

All 2 Replies

Hi, you could use the explode() function:

$data = array();

foreach($input as $key => $value)
    $id = explode('-', $key);
    if(array_key_exists(1, $id)) $data[$id[1]][$key] = $value;


The array_key_exists() is used to avoid errors when processing other keys as $_POST['submit'], which doesn't have a dash character and that, otherwise, would create a notice: Notice: Undefined offset: 1 ...

So how does the mystical CHtml::activeTextField(...) render in HTML?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.