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.
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!
Looking over this example: http://emberjs.com/guides/cookbook/user_interface_and_interaction/using_modal_dialogs/
Everything works fine to open/close the modal, but form submission does not work.
For example, take the modified jsbin example:
http://emberjs.jsbin.com/qoyuyalifu/1/
I have an action on submit in the form tag, yet clicking Submit does not submit the form. In other words, it doesn't seem to be recognizing the action on the form tag. Any ideas?
You're expecting the sendForm action to fire but you don't declare it anywhere.
Have a look at his JSBin: http://emberjs.jsbin.com/ruqikokoti/1/edit
I added the sendForm action in ModalController
I have one search form with search button and some field, when I put value in form field and click on search button then come back on form by clicking on link(modify search form) then form value does not reset...Please check it here(http://dev.viawebgroup.com/search/)
Thanks
Try this:
<script>
function test(){
var input = document.getElementById('search');
input.value = '';
};
</script>
Add onload to the body:
<button onclick="test()">Clear</button>
Add id to input field:
<input type="text" id="search">
Fatal flaw rests form befor data is sent
The simplest way I found is
onsubmit="this.reset()"
Just put this in the form tag and all's well, simple yet efective.
I someone wanted a button excluesivly for form reset I would use onclick and write the reset in a function like this.
function clform()
{
documentgetElementById('myform').reset();
}
The first is tried and true, the second I just wrote but should work.
The function works well used in a onbeforeunload event in the body.
I have been working on this problem my self because the page I wrote is dynamically updated and was keeping form data when back button of browser was used. I also used PHP to reload the page after submission and onfocus to reload the page when form is selected so input is on a fresh page and not the dynamically updated page.
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.
Is it possible to post the same form to different controllers?
Each page could be post only to form action url, but may be some how i may say to button to which url form should go?
e.g i have one form and two submit buttons, one button will post form to one controller/url (eg /action/view) anther button submit form to one to another controller/url (eg /action/anothervew).
You can definitely do this, use JQuery (or just javascript) to attach a function to the onclick event of the button(s). Then use that function to change the URL that the form posts to and then submit the form.
JQuery would be something like:
$('#button1').onclick(function(){ $(this).action = url1; $(document).submit();});
$('#button2').onclick(function(){ $(this).action = url2; $(document).submit();});
You will need to use javascript for this. When the button is clicked have the javascript modify the form's action property to the appropriate controller and then submit the form.
We've done this before using javascript, as mentioned in other answers, and that's probably the correct way to go. An alternative, however, is to post to a single controller method which contains logic to decide where to send the form data off to.
Effectively, you submit the form to the controller, and the resubmit that data based on the text or id of the button clicked using an if statement in the body of the controller action.