Skip to content Skip to sidebar Skip to footer

Update Form Field With Js But Not Showing In Submitted Data

Experimenting with JsHelper in CakePHP 2.0, I got a Request method to update the value of a form field with the results of an AJAX call - so far, so good. However, on inspecting th

Solution 1:

You need to set the value attribute:

<inputtype="hidden" value="YOUR VALUE HERE" name="data[Etc][field]" />

You don't wrap a value in input tags.

Solution 2:

OK. I have found a workaround and no one else seems to have found a direct solution.

In my static view I now have just <td id="part"></td> where the input field was. My Ajax call now updates '#part' and my dynamic view (the one called by the controller ajax action) now outputs the whole field - <?php echo $this->Form->input('unitcost', array('type' => 'text', 'value' => $part['Part']['costamount'])); ?>. Ugly but it works.

Solution 3:

$this->Js->get('#JobsPartPartId')->event('change',
 $this->Js->request(
    array(
        'controller'=>'JobsParts',
        'action'=>'getPart'
    ),
    array(
        'success'=>'$("#JobsPartUnitcost").val(data)',
        'async' => true,
        'method' => 'post',
        'dataExpression'=>true,
        'data'=> $this->Js->serializeForm(array(
            'isForm' => false,
            'inline' => true
        ))
    )
)

);

Post a Comment for "Update Form Field With Js But Not Showing In Submitted Data"