Naphstor
Naphstor

Reputation: 2496

display confirmation message on submit in zend php

Hi I have created a zend_form_element_submit. Now i want to display a confirmation message when someone clicks on submit. And when the user selects yes or ok, the form should be submitted. I read about javascript confirm() function, but was wondering if there is anything provided by zend.

Upvotes: 1

Views: 1559

Answers (4)

Sara Fuerst
Sara Fuerst

Reputation: 6098

On the button you can set an attribute:

$button->setAttribute('onclick', 'if (confirm("Are you sure?")) { document.form.submit(); } return false;');

Upvotes: 0

Wil Moore III
Wil Moore III

Reputation: 7214

The FlashMessenger component is what you need in this case. You can choose to render the messages via direct HTML or via JavaScript.

FlashMessenger Action Helper

FYI: you can build a partial view template which only gets rendered if there are >0 messages.

Upvotes: 0

aporat
aporat

Reputation: 5932

To do that, you should assign an identifier to your Zend_Form subclass and assign a javascript submit handler to that form.

To assign an id to the form, use the setAttrib() function in your Zend_Form::init() function:

/**
 * init the form
 */
public function init()
{
    $this->setAttrib('id', 'search-form');  
    .....
 }

and then you can use this event handling code to override the form's submit function:

// submit search form
$('form#search-form').submit(function() {
        if (confirm("....")) {
           return true;
        }
       return false;
    });

Upvotes: 0

Liyali
Liyali

Reputation: 5693

You can do it using Zend Framework but in my opinion, I think it's more user-friendly to use javascript to handle this kind of thing.

For example, you would trigger a jQuery Dialog (modal confirmation) once the user click on the submit button. More information about jQuery Dialog here.

Upvotes: 1

Related Questions