cakephp 3.0 model filed form hyphen underscore - cakephp-3.0

Today I ran into this problem. There should be some simple solution, but I guess I am too tired to find it...
In one of my tables there is a field 'workplace_address'. I would like to update it via ajax.
My input field is echo $this->Form->input('workplace_address); which generates this:
<input type="text" id="workplace-address" name="workplace_address">
The controller gets the posted data, so I have $this->request->data['workplace-address']
Still the submitted data is missing after patching data
$contact = $this->Contacts->patchEntity($contact, $this->request->data);
Is this some hyphen / underscore problem, or I just do not see something obvious?

Related

Django save/update not change data in database

Django 1.11.7
MySQL
I was trying to change the value of an object like this:
# change the value of the filed and save
def patch(...):
instance.field_name = new_name
instance.save()
print(instance.filed_name)
When I run the code I got the print result as new_name. But when I check the database manually I got the result as old_name.
Then I tried ways like:
instance.save(update_fields=['field'])
and
ModelName.objects.filter(id=instance.id).update(field_name=new_name)
but get the above problem as well. And meanwhile, the project runs perfectly functional except for this segment of code.
Any idea what caused this problem or suggestion on how to solve it?
Is that piece of code inside a transaction? Maybe the transaction gets rolledback somewhere later.
When you read from the DB are you inside a transaction? Some transaction modes may not show you this change.
Are you sure that field_name is the correct field name? Maybe you have a typo and you just set a property of the object without changing model field. From what I see you sometimes type "field_name" and sometimes "filed_name"

what else can i use instead of htp.print and dbms_output on toad for oracle PL/SQL?

At the moment i have htp.print and DBMS_output to show the me the end result of user input. however, htp.print shows the confirmed message on the web browser and my DBMS_output doesn't work for some reason. But what i'm looking for is the confirmation message which will pop up and show to the user. i have tried java script and for some reason that is not working either. below are the syntax.
-- button and input text field
HTP.FORMOPEN ('BANINST1.UAP.P_UNSUSPEND_SEARCH', 'post');
HTP.P ('<input type="text" method="post" name="bannerid" id="bannerid" placeholder="e.g. 000123456" maxlength="9"
autocomplete="off" required>');
HTP.FORMSUBMIT ('', 'Submit', cattributes => 'onclick="confirmMsg()"');
HTP.FORMCLOSE;
-- javascript confirmation message which is not working
htp.p ('<script type="text/javascript">
function confirmMsg() {
var field1 = document.getElementById("bannerid").value;
alert(field1+" has been unsuspended");
}
</script>');
Assuming you are looking for ways to generate log messages from the DB Backend, I see basically 2 ways to achieve this:
(1) Persist your messages to a table inside an autonomous transaction. A complete example can be found here.
(2) If you have access to the DB servers file system, you can also write messages to text files using the UTIL_FILE package.

Saving values containing comma's in a HTML Multiple select

I have a HTML multiple select being used which caused no issue until a selection with a comma was entered. When saving / loading the values are split by ',' into a list. Therefore causing an issue
I have tried to find a way of possibly changing the character that is being used to split the values when the form is posted but came to a dead end.
Would be very grateful if someone has any insight into this.
Thanks in advance.
---Update with Code---
The control is created dynamically
Dim SelectName1 As New HtmlSelect
SelectName1.ID = "SelectName" & id
SelectName1.Name = "SelectName"
SelectName1.Multiple = True
and filled by looping though the values.
For Each value As String In Request.Form(idToFind).Split(",")
If Not IsDBNull(SelectName.Items.FindByValue(value)) Then....
I cannot add any more code than that, Apologies
After updating the question by add code, I think the available options are limited:
Create an extra Javascript method, that stores the selected values in a json object and store it into a hidden input field. I'm not an expert in asp.net, though I'm sure there exists a method to parse json objects from a string.
Create an extra javascript method, that concatinating all values to a String and store it into a hidden input field. With creation of a single string, you can define your own delimiter.
After that, add this extra Javascript mehod to the event onSubmit. Then submit the form and read the value from hidden input field.
P.S. In my eyes the second idea is more simple to create, than the first one. And maybe there are better ways.

returned string from input.getAttribute('value') is missing a character

I am developing e2e-tests for an angular application but I've run into an issue. I am retrieving the value from an < input type="text" /> with the method .getAttribute('value') but it is missing a single character. I've checked the HTML properties of the element which holds the value and it displays it correctly. I've retraced the steps manually in the application and there it is displayed correctly as well. It seems very unlogical to me, but perhaps someone has had experience with this issue. Thanks in advance.
HTML code:
<input class="form-control ng-pristine ng-untouched ng-valid" ng-model="schedule.cronValue" id="cronValue" disabled="disabled">
Protractor code to retrieve the value of the element:
//fill our CRON variable with the generated CRON value
element(by.id('cronValue')).getAttribute('value').then(function(attr){
CRON = attr;
});
The expected output is the value from my database. The CRON value, is retrieved from the input type text.
Screenshot of the situation if needed: http://imgur.com/Co4mGyL
Console.log output:
Expected value:0 0 0 1/1 * ? *
CRON:0 0 0 1/ * ? *
As you can see, it is missing a '1' after the '/'.
It is difficult to say without being able to reproduce the problem, but what I would try as a workaround is to use evaluate() and "evaluate" the value of the model:
element(by.id('cronValue')).evaluate('schedule.cronValue').then(function(value) {
CRON = value;
});
If the CRON value would still have the same incorrect value - then, at least, you would know that this value is really set on the model and it is probably coming from the database as is.

Not saving to db if form input fields are empty?

I have created Wordpress custom fields through functions.php. My code works fine, and I've few input fields and some checkboxes.
Problem is when I save post, even if I don't put content inside my form, these rows are created in DB. I'd like to do some kind of php check and avoid creation of row in DB if field content is not saved.
I tried several ways, but in most cases it would result in incorrect behaviors of checkboxes for example.
Full code is here: http://pastebin.com/embed_js.php?i=Vvnseiep
I'd appreciate your help in this matter. I'm not very experienced.
Thanks!
Here Validation part comes into play. Why cant you use Javascript to validate your input in the client environment itself and then allowing it to hit the db.
Name all of the checkboxes the same(name="meta_box_check[]"). They must still have different ID's. When the form is posted you will be given an array of values that were checked in $_POST['meta_box_check']. You can then check if the array is empty. You can also save the checkbox data as JSON data. This isn't always good practice, but will only use one data row to save any and all checkbox values.
<?php
if(!empty($_POST['meta_box_check']))
{
//process your data and save it
update_post_meta($post_id, 'meta_features_checklist', json_encode($_POST['meta_box_check']));
}
?>
This is a basic example and make sure you do some data validating before saving.