Does using the action class of different module causes change in header during form submission? - forms

I have problem with form submission to a action of different moudule, say e.g I have a module called "mymobile" from I am calling a action in module "register" which will process the registration, if there is any error in form I am setting the error messages and forwarding to "mymobile" module's page from where I called the action of "register", so it is modifying the header and my Japanese text is getting converted to some junk. Is there any way I can show error messages on my form without change of text? Any alternative for $this->forward() method? I am using symfony 1.1 and I tried $this->rediect() it will refresh the page.
Thank you in advnace

Related

Stop "?" from being added to URL

I currently have an Angular 2 app where the user can submit a form to create a new item. When the submit button is clicked, it calls a function that sends the data to the server and navigates to a new page when the server confirms that the data has been saved successfully.
My problem comes because the form submission appends the form parameters to the URL. So for example if I had an input named title and submission took me to the route mytitle which is the input for the title field, Angular (or whatever injects the GET parameters) would try to navigate to mysite.com/mytitle?title=mytitle instead of just mysite.com/mytitle. Even adding [ngModelOptions]="{standalone: true}" to all of my inputs still leaves a question mark with no parameters after it.
This is a problem because it causes Angular to reload the app because the given route does not match any routes in my route definitions. Is there a way to disable the GET parameters being injected into the URL entirely? POST doesn't work either because I have nowhere to post to, and my next URL uses data from the form itself.
I found an answer to my question, the "Submit" button defaulted to being of type "submit", so changing it to type "button" removed the GET parameters injection behavior.
Check setValue in your form control. Example: Set value this way this.form.controls['val'].setValue='' rather than assigning an empty value
(i.e. this.form.controls['val'] == 0).
If your problem still exists, kindly add button type submit to the button and manually give the click function access to it.

How to show single form validation error message for multiple form fields in codeigniter

I have a simple form which has only two(email, password) fields. I'm using codeigniter's form validation library to validate that form. And it's working fine, but not the way I wanted to.
I want to show only one error message when email or password field empty. or when both fields are empty. not two error messages for each fields.
How can I do that in codeigniter using it's form_validation library.
Use form_error() function http://www.codeigniter.com/user_guide/libraries/form_validation.html look up Showing Errors Individually

AEM: Display an Alert box after server side validation

I have a form in AEM. When the submit button is clicked control goes to forward.jsp. I have done some validations in forward.jsp and would like to generate on alert on the page once the validation is failed. How can I pass the alert to the page?
if(condition){
// validation success
} else{
// code for alert
}
FormsHelper.redirectToReferrer(slingRequest, slingResponse);
If you want to do the validation server-side, but show an alert client-side, I recommend you use JavaScript to make an AJAX call. You could change your submit button so that when it is clicked, it fires an AJAX call instead of submitting a form. See http://api.jquery.com/jquery.ajax/ for a description of how this could be done using jQuery, but other options would also work for making the AJAX request.
In the response to that AJAX request you can put whetever you need. It can be a status code, a string of JSON, or a blurb of HTML. You then would write client-side JavaScript to handle the response and do whatever is appropriate based on the given response--such as show an alert on the page.
An example of this sort of approach if seen at http://michaelsoriano.com/how-to-ajax-validate-forms/
This topic is more complicated that you might think. Basically you can see sample implementation in the foundation components such as /libs/foundation/components/form/text/text.jsp. They all use the com.day.cq.wcm.foundation.forms.LayoutHelper#printErrors method to check if they are errors on field. This is happening over the com.day.cq.wcm.foundation.forms.ValidationInfo class which is set as request attribute in order to transfer the field state between the different classes. You can check also the com.day.cq.wcm.foundation.forms.FieldHelper class which performs actually the validation. Putting some sort of logic in the forward.jsp is the wrong ways

Validate a file when creating content in Alfresco

I want to upload some XML files to Alfresco, so the create con tent form has an input file form element.
I need to check if the XML is well-formed, and I already have the backend validation functions triggered on ResourceBehavior.onContentUpdate. If the XML is malformed, I want to notify the user with a dialog window.
So far, I can prevent the user to submit malformed XML by throwing an exception when the XML is malformed, but I can't figure out how to have share to display an error message.
I have been looking at all the validation JS in share, but remember, file input forms need to be submitted first so that you can have a look at its content, thus the validation has to be server-sided.
Any pointers on where should I begin?
The problem you are going to have is that your backend behaviour is not aware of the specific client session that made the changes and what client session it is that needs to be notified.
If you want to display a useful message then you are going to have to write some additional Share customisation. Some options which you can explore are having an action or webscript that returns whether the XML is valid or not and customising the Share upload form to execute this action/webscript after the file has been uploaded and then return the relevant message to the user.
You'll find a pretty detailed post on modifying the upload form here:
http://www.ixxus.com/blog/2011/09/customising-upload-files-dialog-alfresco-share
If you're feeling lazy then I'd consider just aborting the file creation if the XML is invalid during an onCreate behaviour and then the user will see an 'Internal Error'.

Allow form submission to server inside of angularJS?

According to the AngularJS doc's https://docs.angularjs.org/api/ng/directive/form
"For this reason, Angular prevents the default action (form submission to the server) unless the element has an action attribute specified."
is there any way to stop angularJS doing this?
If you don't want the form submission to go down the browser handled route don't put the action attribute on the form use the directive ng-submit which basically calls a method on your controller which will allow you to send the data to the server via a xhr request.