How to create form elements with a custom name in cakephp?

advertisements

I am working on existing project. There are many forms like this:

<?php echo $form->create('MyForm', array('id' => 'MyFormId')); ?>

  <?php echo $form->input('User.0.username', array( 'label' => false, )); ?>
  <?php echo $form->input('User.0.location', array( 'label' => false, )); ?>

<?php echo $form->end(); ?>

It is generating form elements like this:

<input type="text" id="User0Username" name="data[User][0][username]">
<input type="text" id="User0Location" name="data[User][0][location]">

Bu I want them to be look like this:

<input type="text" id="User0Username" name="User_0_username">
<input type="text" id="User0Location" name="User_0_location">

Is there any $form->create(); function option to get this html instead of changing my forms elements?

Thanks


I always use the bracket version - even for jquery ajax submit. this way it works, by the way:

var ids = new Array();
var myCheckboxes = new Array();
$("#ProductCalculation input:checked").each(function() {
    ids.push($(this).val());
});
...
$.ajax({
    dataType: 'json',
    type: "post",
    data: {
        'data[Product][product_calculation_id]': ids,
        'data[Product][brand_id]': brands,
        'data[Category][Category]': categories,
        'data[Form][connect]': c
    },
    url: targeturl,
    beforeSend: function(xhr) {
        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    },
    success: function(html) {
        ...
    }
});

you can manually grab the form elements. not ideal, but it does not break cake-styled coding

i am also sure one could write a jquery plugin to make this automatically in some way. that is actually quite an interesting thing to do.