1
votes

I have a form in my CakePHP with two submit buttons like so:

<div class="form-actions">
    <button type="submit" name="preview" class="btn btn-large">Preview</button>
    <button type="submit" name="save" class="btn btn-large">Save</button>
</div>

However because I've given them both names it returns with an error that the request has been black-holed due to the security restrictions.

How do I get around this? As I want to do different things in the controller dependant on which button was used to submit the form.

3
is there a compelling reason for both to be submits? why can't use call preview a type=button instead? - Brad
Because type button won't submit the form. - Cameron
You can use js, is that an option? - Ofir Baruch
well if cakephp has issue with you having two submits, why don't you semantically call one a button but use JS to submit it? - Brad
What if I add fake Schema to the Model? - Cameron

3 Answers

1
votes

Does it work if you give them both the same name but different values:

<input type="submit" name="submitButton" value="Preview" />
<input type="submit" name="submitButton" value="Save" />
1
votes

Can you do this instead?

    <div class="form-actions">
        <button type="button" name="preview" class="btn btn-large">Preview</button>
        <button type="submit" name="save" class="btn btn-large">Save</button>
    </div>

$(function() {
     $(".btn.btn-large").on("click", function(){
           $( "#yourForm" ).submit();
     }); 
});
0
votes

Doing this works:

<?php 
echo $this->Form->submit('Save and Preview', array('div'=>false, 'name'=>'submit', 'value'=>'preview')); 
echo $this->Form->submit('Publish Post', array('div'=>false, 'name'=>'submit', 'value'=>'publish')); 
?>