Unobtrusive Javascript Validation with MVC 3, is preventing me validating form manually - asp.net-mvc-3

For 90% of my site the standard MVC annotation with client script method is working a treat. But I have a form on the site that is quite complicated with multiple instances of dynamic form content dependant on answers to questions etc.
If I have the unobtrusive script included on the page, it's capturing the form submit and not allowing my custom jquery validate to validate the form.
I don't really want to refactor the site to have a seperate layout to remove the script when it's not needed. I wondered if there was an easy way to give control back to my custom validate script.
Any help would be great.

In your view you can disable client side validation like this
Html.ViewContext.ClientValidationEnabled = false

Related

What is the best way to place 2 forms on the same page?

What is the best way to place 2 identical forms on the same page, but use the same form action and fields for each form? How can I keep response messages in the respective form area from which the data was submitted?
I'd have one form in the footer of my site, and one form in a popup on the home page of my site. I'm using a hidden div and Magnific to open the popup containing the same code from the form that is located at the footer. Essentially, both form do the same thing, and utilize the same form action.
I do not have access to the form action, or the code in the form action page.
Currently, the forms existing on the same "page" are no problem, but when I submit an email on one form, the errors and success messages show up on both the popup form as well as in the footer form.
I've read that this may be possible to do with ajax, but for completeness sake, I want to make sure that I'm building that I'm doing what I can with the form html, before moving on to studying ajax for this.
Sadly there is no nice html/liquid solution for this.
The only way is to use cookies in order to save information which form was submitted and show the error message only for that form instead of the two ones.
AJAX is not a good solution because of the Google Recaptch-a when you submit the form more than once, which is a real pain in the a** since there is no way to disable it and the form will fail if you try to submit it with ajax.
The easiest solution is to use cookies, other option is to rely on an APP for this, but it may be an overkill for this.
Forms in Shopify are... how to put it nicely... dumb... basic... not developer friendly or just not made to be tweaked in any sort of way ( excluding the front-end ).

AEM OOTB Form Component and AJAX Submission

I'm evaluating AEM 6.2 OOTB forms component to build a Newsletter signup form with AJAX submission, this is not AEM Forms that is licensed separately.
https://docs.adobe.com/docs/en/aem/6-2/develop/components/developing-forms.html
I have not used this component previously, can someone advise on the following:
Can I make the form submit request via AJAX and capture response from the server side / API (asynchronous)?
Is there limitation in terms of styling capability? I'm trying to achieve the same signup form at the bottom of this page https://westernstarbutter.com.au/en/recipes/ham_-cheese-and-veggie-bake.html
Any other limitations / gotchas that I should be aware of?
Would love to hear some advices on this, would be great if someone can share some implementations as well.
Thank you!
Can I make the form submit request via AJAX and capture response from the server side / API (asynchronous)?
I don't believe you can do this OOTB - it's certainly not part of the actions list but it wouldn't be too hard to create a custom action and add the necessary Javascript code to hook into the form submission.
Is there limitation in terms of styling capability?
Not really - just add your own CSS and off you go.
Any other limitations / gotchas that I should be aware of?
I remember the validation being very limiting, especially if validation of a field is dependent on another field.

MVC 4, Jquery Mobile, Ajax.BeginForm causing forms to submit twice

Does anyone know of any bugs or other insight to explain why when using MVC4 with jquery mobile, any form that is created using Ajax.BeginForm results in the form being submitted twice to the controller.
I had originally thought that since I am using the js bundling that the same js file might have been being included twice and might be triggering on form submit, however thats not the case, my list of js files are:
jquery-1.6.4.js
jquery-ui.1.8.11.js
jquery.mobile-1.1.0.js
jquery.unobtrusive-ajax.js
jquery.validate.js
knockout-2.0.0.js
MicrosoftAjax.js
MicrosoftMvcAjax.js
MicrosoftMvcValidation.js
Modernizr.js
Within the project Ajax is fully enabled for everything i.e. i'm not disabling anything through mobileinit.
I have not posted any form code because it literally happens with every form - a form with one field and a submit button will cause the submission twice - but only where Ajax.BeginForm is being used.
Html.BeginForm doesn't exhibit any of these problems.
I've been stuck on this for a few days now so any help would be greatly appreciated
jQuery Mobile by default hi-jacks any form submission and performs its own AJAX request. To stop this behavior you can place the data-ajax="false" attribute on any <form> tag. Also make sure to stop the regular behavior of the form so it doesn't submit normally, something like:
$('#my-form').on('submit', false);
Docs: http://jquerymobile.com/demos/1.1.0/docs/forms/forms-sample.html
You could also just use the built-in jQuery Mobile AJAX rather than including extra JS for it. Which would only require you to make the action attributes of the forms to the server-side file to which they posts.

MVC3 AjaxHelper choosing selected DDL values without custom javascript

I'm creating a site where I don't want anything to be done via custom javascript/jquery code at all, and I'm not sure it's going to be possible so need some advice.
The things that I want to be able to do are:
Load a JQuery (or Jquery style) dialog box containing a partial view.
Have a button that will select the "SelectedValue" from a dropdown list and render a partial view. (e.g. select a user from a dropdown and then click a button to add them to a list)
Append a partial view to an existing div.
I'm sure that all the above can be done using custom javascript, but what I want to is to use the standard Ajax and Html helpers that come with MVC3.
Main reason is that I've been struggling to get to grips with jQuery, but I also thought it would be nice to see if it can all be done without having to add a new script to the site.
As always, any help is greatly appreciated (even if it's just pointing me to articles).
The standard Ajax and Html helpers that come with MVC3 are for handling server-side stuff. Even the #Html.ValidationMessageFor helper usually uses their unobtrusive validation lib for jQuery validate.
Keep trying at jQuery, you'll get it. There is a reason it is so popular!
Update
I believe you can do #3 using #Ajax.ActionLink, but don't think you can do 1 or 2 out of the box with the Ajax html helper.
It seems that you can use the Ajax.BeginForm method to do this.
There are issues with the fact that it has been in a separate form as I can't nest the forms though.

Good practices for handling form submission on codeigniter/php website

I'm building a website with codeigniter and I'm creating a form for user submission.
I'm thinking about having the form submit with an javascript/AJAX call to a special controller intended just to handle form submissions and redirecting the user to an appropriate page based off the response from that controller.
Is this a good idea? I imagine my site will have lots of forms so I'm thinking a special controller just to handle their submission is a good idea. But obviously I will need to prevent users from ever directly accessing any of the methods in this controller.
Make sure your form works without javascript, and then you can use $this->input->is_ajax_request() to check if the form is being submitted with ajax, and do something different with your output.
This avoids the need for "ajax only" controllers, methods, and URLs, and keeps all your form processing logic together in one place. If it's not an ajax request, no one will ever be able to see the output so you don't need to worry.

Resources