CAKEPHP Confirming on Submit

cakephp, forms

Solution

You need to use double quotes:

<?php 
echo $this->Form->create('Shift', array(
    'onsubmit' => "return confirm(\"Creating shift for '$id' on \");"
));
?>

Another option is to use $this->Form->postLink() and set $confirmMessage parameter if it is a simple state shift form.

Problem

I have a submit button in my form like this : ``` <?php echo $this->Form->end(__('Submit')); ?> ``` and I want to embed variables that are part of the input form. For example, I want to embed a variable that is input here `$this->Form->input('user_id');`. Does anyone know how to do this? I currently have this `onsubmit` as part of the options array, but it throws errors when I try to embed variables. ``` <?php echo $this->Form->create('Shift', array( 'onsubmit' => 'return confirm("Creating shift for '$id' on ");' )); ?> ``` Now making an edit to this question. So the Javascript solution worked fine. Issue now is that I want the alert box to display the user's name, which is what is displayed in the dropbox. However, the HTML tags contain the user's ids. Here is the HTML ``` <div class="input select required"> <label for="my_user_id">User</label> <select name="data[Shift][user_id]" id="my_user_id" required="required"> <option value="1">john doe</option> <option value="2">john johnson</option> ``` Is there a way to access the value between the `<option>` tags using Javascript?

Original source