Field value fetch when field name is not known - json

I am using a form builder using which my admin side can create forms and store it as JSON. They are rendered dynamically when the client accesses these forms. When the client submits the form at the back end I need to get the value of all the fields.
Currently I am trying to do this as follows:(Node Server)
router.post('/increase', function (req, res, next) {
req.session.counter++;
var ans = req.body;
console.log(ans+" this got printed");
res.redirect('docfill');
});
I cannot specify a name after req.body as i dont know the field name due to the dynamic nature of the forms.
The console prints [Object object]. The currently rendered form has a date field I need. And if I put it through JSON.stringify() it prints {}. Is my fetched data coming out to be blank? Could it be a problem with using the data field.
EDIT
its not because the filed is a date type, dosnt work with text either

There could be 2 reasons for this:
You have not installed/required the bodyParser module.
In your form tag you're using the enctype attribute as enctype="multipart/form-data". Reason for this being you're not using any module for handling the multipart/form-data type which is unreadable by the browser. Use enctype="application/json" instead.

Related

Angular 4 - BehaviourSubject not returning json data properly

I'm trying to creating a global service in angular app with BehaviorSubject.
I have created a method in this service where I have defined a HTTP get method and loading JSON file.
Now the issue I'm facing is when I'm subscribing this BehaviourSubject as asObservable in any component and assign the result to a particular variable in the typescript file, the HTML template renders this value correctly via structured Directive *ngFor but when I'm trying to get the same value in typescript file, it does not work.
For example;
When I'm trying to print this value
console.log(this.data.boxes.length);
then it gives me an error
[ERROR TypeError: Cannot read property 'length' of undefined]
and when I'm trying to print this value without length
console.log(this.data.boxes);
it gives me a proper value of an array in the console panel.
Now If I change BehaviorSubject to Subject, then its working fine means I am also getting length value.
However, I want to use BehaviorSubject instead of Subject.
What am I doing wrong and how can I achieve it?
Behavior subject is emitting current value to subscriber even if subject next is not called before subscription, in other words:
yours subscription is subscribed to subject before first "next" value. I assume that initial value of behavior subject is undefined or similar, so that first value that is emitted to subscriber is causing error.
Could you check declaration of subject and ensure that initial value is in correct form, like:
public exampleSubject = new BeahviourSubject<yourType[]>(<yourType[]>[]);

ColdFusion convert hidden form variables to a structure

The app I am working on has hidden input variables set on initial load of the page. The variables need to be accessed across all pages. The reason for not converting these to session variables is the user can open another browser with different parameters and passing those value as hidden inputs make it work without any issue. What is the best possible alternative so as to get rid of these hidden inputs..I tried converting all variables into a Structure, but again the structure needs to be posted as part of form submission to make it available to subsequent pages.Another disadvantage of this app is use of frames.I don't have any code to post.
It sounds as if you want different browsers instances which are associated with the same web session to maintain their own distinct sets of data. Doing this by passing form or url variables around seems like a bad idea.
One approach that you could use would be, onSessionStart (or as required), create a structure in the users session to hold instances of the data. For example
session.data = {
someRandomKey: {
valueA: 42,
valueB: "Porridge"
}
}
Then just pass someRandomKey as a hidden form field or querystring parameter. Now, when they submit the form to update variables you use the id from the hidden form field to find the appropriate structure from session.data.
When the user needs a new instance of this form, give them some way, like a link or button, that creates a new unique key, inserts a struct in session.data with this key and populates it with whatever defaults are needed then loads the form passing along the new id as a hidden form field or querystring param again.

In Talend, how do you keep input values provided to tSoap so that you can use them with the Soap response?

I have a Talend Job that currently does the following:
Input CSV --Main--> tMap --Output--> tSoap --Main--> Output CSV
The input CSV has
ID and TYPE as input columns.
The Map creates a Soap XML (String) message using the ID from the CSV and passes that String to the tSoap component.
The tSoap component fires the web request, which sends the response to the next component. That data is then written to CSV.
The problem is that TYPE from the input CSV is not passed through to amalgamate with the SOAP response data. Only the response data seems accessible.
I've had a look at tBufferInput / tBufferOutput and tFlowToIterate but they seem to work in scenarios where the tSoap component does not depend on an input from the main flow.
Does anyone know which components can be used to achieve the amalgamation?
Thank you
If you output the data you need to reuse to a tHashOutput component you should be able to rejoin your data with the response output from tSoap assuming there's some natural join element from the response.
I solved this in the end by:
Placing between the output from the tMap and the input to the tSoap, a new component - tSetGlobalVar
Inside tSetGlobalVar, you can then create a new row, which maps an input column (Value) to a named variable that you specify as the 'Key'.
E.g. Key = "ID", Value = row11.ID
The output from tSetGlobalVar then goes into the tSoap component.
The output from tSoap goes into a new tMap.
Inside this new tMap is the Body column from the previous tSoap component which maps to an output column. To access the stored "ID" variable for the current flow/iteration, I created a new output column, and instead of mapping any columns from the inputs, used (String)globalMap.get("ID"); which would insert the value back into the flow.

Trying to overwrite pre populated data in an input area

I am trying to display an input area in a Jade file with pre-populated data gathered from the session info being stored in mongodb session store. The web app is built on Express for node.js. My Jade file looks like this with the input area (pre-populated with session data):
input(name='username', value='#{username}')
So the input area is displaying the correct username stored in the session. Then, I want the user to be able to edit that field and submit a new username if desired. My mongodb update() looks like this:
uname = request.body.username;
targetcol.update({username: req.session.username, password: req.session.password}, {username: uname});
Once submitted however, the document in the mongodb collection for the related profile is not being updated, it's keeping the same value that's been pre-populated. I'm wondering if this is because I'm assigning it as a value= in the Jade file? Any advice on what is wrong and how to fix it?
Assuming you are using a form, access the value attribute of the input with name username from your route handler function using req.body.username:
app.use(express.bodyParser());
app.post('/form', function(req, res){
var newUsername = req.body.username;
targetcol.update({ username: req.session.uname, password: req.session.password}
, {username: newUsername});
res.redirect('/');
});
The answer was on the mongodb update() side of things. I left a big part out of my question apparently... The selection criteria was actually this:
input(name='username', value='#{username}', disabled)
I didn't realize disabled fields would pass in undefined values, I just thought it made them un-editable. So the update() wasn't working because it couldn't find any matching documents in the collection because username was undefined. You know what they say about assumptions!
I'll credit you #Plato with the answer though, the hint to investigate the values is what lead me to figure this out.

Populate plugin not working correctly

Hi i'm trying to retrieve and populate a form. The following link with username Testing and password test123 .
The page is returning a correct JSON object (I tested it by putting on screen between paragraph tags) but the populate plugin is not populating. In firebug it show "no such element as" without displaying the element's name. The input field names are exactly the same is in the DB.
any ideas?
The problem is that your success callback gets passed a string argument, instead of the expected Object/Array, which causes the populate method to treat the whole input as a single unnamed value. This is caused by a typo in the options object passed to your $.ajax() call:
$.ajax({
// ...
datatype: 'json'
});
The option names are case sensitive and the correct spelling for the datatype attribute is dataType with a capital tee. By default, if the datatype option is missing/misspelled, jQuery will try to intelligently guess the datatype of the response and return the result as a formatted string (see the jQuery documentation). So just rename the datatype option to dataType and your fields get populated correctly.