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.
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.
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;
});
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.
On the button you can set an attribute:
$button->setAttribute('onclick', 'if (confirm("Are you sure?")) { document.form.submit(); } return false;');
Related
I am using <q-modal>(Quasar Framework) for a form. On clicking Add button a form will pop over. In this, I am validating each form tags, after clicking submit button. To close the modal, I am using #click="$refs.maximizedModal.close()" for submit button.
Everything works fine. Now I need to retain modal if the validation is not returning true or if validation satisfies then the modal need to be closed.
Is there any method to do conditional submit in Vue js?
You should make a custom function for the submit of the form and use it, something like this :
....
methods{
checkForm(e){
if(VALIDATION_IS_TRUE){
//Validation has passed, we submit the form OR close the modal
$refs.maximizedModal.close(); // Maybe this.$refs.maximizedModal.close()
e.target.submit();
}else{
//The form is not validated, do something to inform the user
}
}
}
and instead of using the #click for the submit button, add this to the form element :
<form #submit.prevent='checkForm($event)'>
Hope this helps!
I have a few pages with a form. Every form has a AjaxButton for submitting and a
<div wicket:id="feedback"></div>
for the feedback panel. Every form field is required and the FeedbackPanel gets correctly filled with error messages from validators in case you leave one field out. The problem is those messages are displayed only if I hit "back" on the browser and then "forward" to see the page again, no matter where I place the feedback <div> inside the page.
Until the back/forward gesture, no error message appear, but the form does not reach onSubmit() (obviously, there are validation errors).
The problem is common to all of my pages that have a form and a FeedBackPanel. All pages make use of Bootstrap 3.2.0, just in case that could make any difference.
Any clue about what's going on?
When you using Ajax, you have to add components, which you want to be updated into AjaxRequestTarget.
Components, which will be updated by Ajax must have predefined markup id.
So, you have to call setOutputMarkupId(true) method for your FeedbackPanel and override onError method for AjaxButton :
... = new AjaxButton (...) {
...
#Override
protected void onError(final AjaxRequestTarget target, final Form form) {
/*here add your feedback panel to be updated via ajax*/
target.addComponent(feedbackPanel);
}
}
I am trying to implement a payment module in ember. I have created a form and on the form action have assigned the server address to which form will be submitted.
<form action="https://api.mondido.com/en/v1/transactions" id="payment_form">
In simple jquery I am supposed to do something like this
var onSuccess = function(transaction){
alert(transaction.id);
};
var onError = function(error){
alert(error.description);
}
$('#my_form').mondido({type:"ajax", success:onSuccess, error:onError});
But I want to wrap it around in some action in the controller. The problem is when I do something like this
<form action="https://api.mondido.com/en/v1/transactions" id="payment_form" action{{someFunction on="submit"}}>
the action is being called twice. I have to click on the submit button twice to get it going in the first attempt and then it is being submitted twice.
Any thoughts how to go around with it?
Its probably because you have two actions defined in your form. Try to remove
action="https://api.mondido.com/en/v1/transactions"
from your form tag, and handle the form submission in your controller.
I'm a beginner when it comes to zend framework.
I created a form with a submit button, using zend_form, and zend_form_element_submit. Upon clicking submit, the code performs data manipulation based on the input. If no input is keyed in, nothing happens.
When I click the submit button, it reloads my web page even though there are no changes.
Any way I can prevent that page load? Could I use a zend_form_element_button that would trigger an event? how would I capture it?
Any help will be mostly appreciated!
Thank you.
A submit button will always cause the form to submit which generally results in a page being reloaded whether or not the data in any of the form elements are "correct" or not.
Using Zend Framework, you could add a JavaScript onsubmit event to your form that could inspect the form elements and decide if the form should be submitted or not. Or you could use Ajax to submit the form which wouldn't result in the page being reloaded.
Here is an example of using onsubmit. You would create your form on the controller, assign it to the view, and then in your view, add the onsubmit attribute and relevant code.
view.phtml
<?php
$this->form->setAttrib('onsubmit', 'return checkForm()');
echo $this->form;
?>
<script type="text/javascript">
function checkForm()
{
if (form_passes_validation) {
return true; // form will submit
} else {
return false; // form will NOT submit (if javascript is enabled)
}
}
</script>
You will have to come up with the logic for form_passes_validation, but if onsubmit returns false, then the form will not be sent.
Keep in mind, PHP is all server side. You can't do any PHP processing to determine if the form should send, this all has to be client side, or you will have to live with your form reloading the page even if no data is entered.
I want to build a simple form with Sencha Touch, and attach a submit handler to it. Either I'm a n00b, or this is surprisingly hard to do. Here's what I want:
Attach an onSubmit handler to the form, not a onClick handler to the submit button
Cancel form submission when the form is submitted.
The problem is that regular Sencha Touch buttons are not buttons at all - they are just a bunch of divs and spans. Hence, tapping on the submit button doesn't fire the native form submit. As a result, a handler will need to be attached to the "button" to fire a submit on the form, and then capture the submit of the form to do what I want. This is doable, but doesn't sound elegant. Is there a better way of doing this?
The second problem is that of event canceling. How do I get a handle of the submit event object so that I can call preventDefault on it? Is there any other way to do this in the Sencha Touch world?
If you want to perform a stand submit action on a form, you need to set the "standardSubmit" config property to true, which will force a standard submit when the form is posted.
And yes, you must attach an event handler to a button but it' very easy. All you have to do is setup the button like so:
{
xtype: 'button',
text: 'Next',
handler: this.tapHandler //<= common tapHandler for the page
}
Then setup a handler like so:
// Toolbar button handler function
tapHandler: function (button, event) {
switch (button.text)
{
case "Submit":
myForm.submit({...config object see API...})
// to cancel event simply return false
return false;
break;
}
}
You have got an option "submitOnAction: true,", which lets you submit when user clicks button Ok/Go on the virtual keyboard on mobile device (works fine for iPhone/iPad).
app.views.newItemForm = Ext.extend(Ext.form.FormPanel, {
submitOnAction: true,
activeItem: 1,
...