How to get global error message? - scala

I use a custom form validation in a controller:
verifying ("URL is already exist. Please choose another one.",
fields => models.DAUser.IfUrlValid(fields.email,fields.url))
In a view, I try to get the global error message by this:
#for(error <- data.globalErrors) {
<p>#error.message</p>
}
But what I get is:
FormError(,URL is already exist. Please choose another one.,WrappedArray())
How to just get the message ("URL is already exist. Please choose another one.")?
Thanks.

Related

TYPO3 v11.5 #1578950324 RuntimeException - The given page record is invalid. Missing uid. Backendmodul

After upgrading to TYPO3 v11.5, I get this error in my extensions backend module:
1578950324 RuntimeException
The given page record is invalid. Missing uid.
So I digged a little deeper and found out that this has to do with using the f:be.tableList ViewHelper.
In my BE module I use the ViewHelper like this:
<f:be.tableList
tableName="tx_myext_domain_model_mymodel"
storagePid="1"
fieldList="{0: 'column1', 1: 'column_2'}"
sortField="column1"
enableControlPanels="true"
clickTitleMode="edit" />
Since I register my backend module with 'navigationComponentId' => '', (as mentioned in the documentation) I get this error. But the page tree or something else isn't helpful at this point, so I don't want to show them.
(If I show the page tree with 'navigationComponentId' => 'TYPO3/CMS/Backend/PageTree/PageTreeElement', this error disappears)
It turned out that the ViewHelper checks if the user has access rights via checking if the PID is in the mountPoint. I think this is important and not a bug. Fixing that issue could be hard, because how to check the mountPoint permissions if I don't know the PID. (maybe in the ViewHelper: check against the storagePid?)
But if you disable the page tree, there is no PID to check against.
So I also found out, the current PID is fetched while TYPO3\CMS\Core\Utility\GeneralUtility looks for a given id like this:
$value = $_POST[$var] ?? $_GET[$var] ?? null;
I didn't found a way to set the pid in my Extbase Controller, so I did it easily this way in my listAction:
if( TYPO3_MODE == 'BE' ) {
// if is in the BE-module, set PID to prevent customer authentication check error
$_POST['id'] = 1;
}
(In this case, I set the PID to my rootpage.)
If someone has a better solution, don't hesitate to post it to this question.
Have you disabled the page tree for the backend module? If yes - that's the problem! The settings inheritNavigationComponentFromMainModule => false leads to the error.

odoo12 how to show success message without break

everybody, please help
in odoo, i know that the error message showing was use raise UserError(), but this function will break the function and rollback in database, what i want to do is just simplely show the successful message to user without break, like operation was successful!.
of course, i have try to use the wizard, but the footer is not working, the page always show the save and discard
appreciate if anybody can help me on this.
thanks.
In that, you can use the onchange API to work around this,
#api.onchange('my_field')
def my_field_change(self):
// warning message
return {
'warning': {'title': _('Error'), 'message': _('Error message'),},
}
With that, Perform the change with your case return the warning message and it does not break the process.You can find a similar behavior on Odoo Sale App on sale order line product change operation.
Thanks

cakephp 3.0 'App\Controller\ContactForm' not found modelless form

I am trying to create a modelless form using cakePHP 3.0, I have been following the guide through the cookbook here http://book.cakephp.org/3.0/en/core-libraries/form.html but it seems I am getting confused as to where to put ContactForm.php. It says to put it in src/Form/ContactForm.php but it did not work. Can someone direct me to this? Thanks
Pls, provide a bit more info about your problem
1) is ContactForm recognized in controller?
if not - check namespace
2) handle your data only in
protected function _execute(array $data)
{
// Send an email.
return true;
}
not in controller's
if ($this->request->is('post')) {
if ($contact->execute($this->request->data)) {
//NOT HERE!!!
} else {
// error
}
}
Also bear in mind that your server configuration may forbid php short open tags.
Make sure your class starts with <?php and not only <? to be on the safer side. If not, CakePHP will simply respond by the Your\Namespace\Class Not Found message.
Just verify where you have put Form Folder, it must be inside src Folder.
Also be sure that the class has Form as suffix.
Because your error is App\Controller\ContactForm not found, that means that you have NOT put Form Folder inside src Folder.

CakePHP 3 and form validation errors

I use cakePHP 3 and I have a sign in form with Form->input().
If on purpose I make an error, this error doesn't whow up under the Form field. It doesn't appear anywhere.
My code is like this:
$newUser = $this->Users->newEntity($this->request->data());
if (!$this->Users->save($newUser)) {
debug($newUser->errors());
$this->Flash->error('Error');
return;
}
Debug show the errors, but shouldn't they appear under each form element automatically?
ok I found the error.
I wasn't passing in Form->create the entiry but null. I did it like
$this->Form->create($entity...
and works nicely.

Validation / Error Messages in ASP.Net MVC 2 View Unrelated to a Property

What pattern can I use to display errors on an MVC 2 view that are not related to a single property?
For example, when I call a web service to process form data, the web service may return an error or throw an exception. I would like to display a user-friendly version of that error, but have no logical means to relate the error to any given property of the model.
UPDATE:
Trying to use this code as suggested, but no summary message is displayed:
MyPage.spark:
Html.ValidationSummary(false, "Oopps it didn't work.");
Controller:
ViewData.ModelState.AddModelError("_FORM", "My custom error message.");
// Also tried this: ViewData.ModelState.AddModelError(string.Empty, "My custom error message.");
return View();
UPDATE 2
What does this mean?
next to each field.
Instead of always displaying all
validation errors, the
Html.ValidationSummary helper method
has a new option to display only
model-level errors. This enables
model-level errors to be displayed in
the validation summary and
field-specific errors to be displayed
next to each field.
Source: http://www.asp.net/learn/whitepapers/what-is-new-in-aspnet-mvc#_TOC3_14
Specifically, how does one add a model level error (as opposed to a field-specific error) to the model?
UPDATE 3:
I noticed this morning that Html.ValidationSummary is not displaying any errors at all, not even property errors. Trying to sort out why.
Simply adding a custom error to the ModelState object in conjunction with the ValidationSummary() extension method should do the trick. I use something like "_FORM" for the key... just so it won't conflict with any fields.
As far as patterns go, I have it setup so that my Business Logic Layer (called via services from the controller) will throw a custom exception if anything expected goes wrong that I want to display on the view. This custom exception contains a Dictionary<string, string> property that has any errors that I should add to ModelState.
HTHs,
Charles