Hello,
I have created text fields

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

    </tbody>
    </table>
    </div>
    </label>

and cloned it using below code.

$("#add").click(function() 
                {
                    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);
                    $clone.attr({
                        id: parseInt(last_tr_id),
                            });

                    $clone.find("input,select").each(function(){
                                var res = ($(this).attr("id")).split("-");
                                var new_id=res[0] + "-"+last_tr_id;
                                $(this).attr({
                                    id: new_id,
                                    name: new_id,
                                    value:''
                                });
                            });
            $($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

array(
1=> //certification 1 values
array(
        1=>
                C_name-1 => certification1
                last_used-1 => 2012
        )
        2=>
                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;
}

print_r($data);

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, networking, learning, and sharing knowledge.