How to post an array of emails as cfhttpparam? - arrays

so I am trying to post to an API using Coldfusion with an array of emails.
For a quick over view of the API schema,
{
"emails":["foo#bar.com", "bar#foo.com"],
"orgId":1,
"subject":"foobar",
"body":"foobar",
"sender":"foobar#com"
}
Now this is my coldfusion script
<cffunction name="inviteusers" access="public" returntype="any">
<cfset var data = "" />
<cfhttp url="urlserver#UserInvite" method="post" username="#username#" password="#urlpass#" result="data">
<cfhttpparam name="emails" this is array or emails>
<cfhttpparam name="orgID" type="formType" value="1">
<cfhttpparam name="body" type="formType" value="this is the body">
<cfhttpparam name="sender" type="formType" value="hmm#yahoo.com">
</cfhttp>
</cffunction>
The emails is where I am stuck at.. I'm not sure how to approach this problem..
Thank you guys!

Allrighty,
here is how I answered this question. Since I am working on an MVC framework, in the view where I have the form, I've created a JQuery post function to the function in a controller.
I have an html input where a user can type in any number of emails separated by comma. I have a javascript function that takes the value of the input and splits them at 'comma' then add them to an array object.
Since the API is structured as this :
{
"emails":["foo#bar.com", "bar#foo.com"],
"orgId":1,
"subject":"foobar",
"body":"foobar",
"sender":"foobar#com"
}
in my $.post() function I have an object for to be used as the data:
var myData = {
"emails" : myEmails, //This myEmails is an array['fooBar#.com', 'barfoo#.com'] of emails from the single email input.
"orgId" : 1,
"subject" : $('#vgridSubject').val(),
"body" : $('#vgridText').val(),
"sender" : "foobar#ls.com"
}
now in my controller, here is how I handle the array of emails
<cfscript>
sendInvites = postUserInvite(emails = FORM['EMAILS[]'], orgID = FORM.orgID, subject = FORM.subject, body = FORM.body, sender = FORM.sender)
</cfscript>
Take note of FORM['EMAILS[]'] as this lets me access the values from form scope.
Link to the form array Working with Form Arrays in ColdFusion?

Related

Dynamic hidden fields values where model name is stored in database

I have a requirement in angular js application where I need to dynamically create hidden variables. Name and value attribute for these hidden fields will be from database. But rather than storing actual value of hidden field in database name of model is stored in a database.
I have written a test function as follows. TempVars will be from database but for time being I have hard coded few values.
$rootScope.populate = function () {
$rootScope.models = {
MyModel: {}
};
$rootScope.models.MyModel.Client = [];
$rootScope.models.MyModel.Client.FirstName = 'FName';
$rootScope.models.MyModel.Client.LastName = 'LName';
$rootScope.TempVars = [
{"key":"var-FirstName","value":"{{models.MyModel.Client.FirstName}}"},
{ "key": "var-LastName", "value": "{{models.MyModel.Client.LastName}}" },
]
};
Following is my HTML code
<input type="hidden" ng-repeat="obj in TempVars" name="{{obj.key}}" value="{{obj.value}}" />
<input type="text" ng-repeat="obj in TempVars" name="{{obj.key}}" value="{{obj.value}}" />
<input type="hidden" name="test" value="{{models.MyModel.Client.FirstName}}" />
I am expecting that hidden filed value should have FName and LName in it. But rather it contains {{models.MyModel.Client.FirstName}} and {{models.MyModel.Client.LastName}} in it. Whereas variable name with name test has FName value stored in it.
Is is possible to achieve this in angularjs?
It won't work that way in angularjs but you will be able to do that through a custom directive and using NGModelController to $format and $parse the data.
Here are some links where you can get the idea about that :
https://egghead.io/lessons/angularjs-using-ngmodel-in-custom-directives
http://radify.io/blog/understanding-ngmodelcontroller-by-example-part-1/

How to retrieve nested json object data with Ionic

I am working with the api from The Movie Database. In my Ionic project I was able to make a http request to pull in some data for a movie. However the json object is a nested json object, so I am having some trouble trying to access the genres of a movie:
For the purpose of this question I will display 1 nested json object:
I want to show the information like so -> Genre: Action - Comedy - Drama
My code for the controller is the following:
$scope.init = function(){
MovieService.getMovieById($stateParams.id).then(function(data){
$scope.trending_movie = data;
console.log($scope.trending_movie);
$scope.genres = data.genres;
console.log($scope.genres);
});
}
If I do this bit of code:
$scope.genres = data.genres;
It just returns met the json object of the genres like so:
The thing is now that I am able to read out the genres but because I access the data with a ng-repeat it will show like this:
How to get the genres on 1 line without having to repeat the word "Genre"?
Here is my html code:
<div ng-repeat="genre in genres">
<p class="movie-info-p">Genre: {{genre.name}}</p>
</div>
you should get "Genre:" out of your ng-repeat and if you want your genres to be in the same line, you shouldn't put them in tag.
There is this solution:
<div> Genre:
<div ng-repeat="genre in genres">
<span class="movie-info-p">{{genre.name}}</span>
</div>
</div>
Another solution is to generate this string in the controller with a for loop and send it to the view

Angularjs filter object parameters

I just get stuck with my code when I am trying to make a filter for my ng repeat div element
I am trying to use one input
<input type="text" class="search_input" ng-model="search">
But in filter I would like to use that search parameter for username and user id.
<div ng-repeat="customer in userList | filter : {customer.username : search, customer.user_id : search}">
So it should show me te correct user with that username or ID what I put to input. How to make it? I am new in angular and I couldn't find for it till now some answers.
You can use a custom filter, take a look at this answer for further information:
AngularJS filter on multiple values of one field
I would comment this, but my rep is too low
create a function in your controller which will return you true/false depending upon your filter criteria :
$scope.fnFilter = function(customer){
return customer.username === $scope.search || customer.user_id === $scope.search;
};
use it in your html as :
<div ng-repeat="customer in userList | filter : fnFilter">

Post full form data to a service in Angular

I have a form that contains a lot of fields and I want to post all the form fields to a service using a post method. But I would like to send the whole form object and not to write one property by one. If I try to post the object that contains all my fields $scope.formData it also contains all the angular stuff inside like errors. What I need is a collection of field names and values. How can I achieve this with minimum coding?
Edit:
I ended up writing my own function:
function getAngularFormFields(form) {
var dictionary = { form: {} };
for (var key in form) {
if (form.hasOwnProperty(key) && !key.indexOf('$') == 0) {
dictionary.form[key] = form[key].$modelValue;
}
}
return dictionary;
}
Normally if you need to post a form you could just use the default method provided by your browser. This will send the form data, via POST, to your URL.
<form action="yourUrlHere" method="POST">
First name: <input type="text" name="fname">
Last name: <input type="text" name="lname">
<input type="submit" value="Submit">
</form>

ng repeat not updating

Hi I am a newbie to angular js and I am hoping someone can help me out with the following problem.
I have a numeric field called numAdults and I need to show a set of field (such as name, address, telephone etc ) numAdult times to get those information for each of those person.
Here is the jsfiddle for the problem jsfiddle link
Here is also an overview of code of the controller
function bookingController($scope){
$scope.numAdults = 1;
$scope.personLoop = function(){
console.log('personLoop called')
return new Array($scope.numAdults);
//return new Array(2);
}
the html
<label for="book_num_adults">Number of adults:</label>
<input id="book_num_adults" type="text" ng-model="numAdults">
<div class="row" ng-repeat="t in personLoop()" style="border:2px solid red;margin-top:10px">
<h4>Person {{$index+1}}</h4>
<input placeholder="name"><br>
<input placeholder="address"><br>
<input placeholder="telephone"><br>
</div>
Can you also help me with how to transform this as an module ( not just a controller based )
Thank you in advance!
Your Fiddle was riddled with errors...
http://jsfiddle.net/bRgTR/5/
Under Frameworks & Extensions, you need to change the 2nd dropdown from "onLoad" to one of the "No wrap" options
Your controller definition is mangled. It's supposed to be: .controller('name', ['depname', function (depname) { })]); -- you had your closing array misplaced.
You should really use semi-colons.
You don't create an array of 5 items in JavaScript like this: var a = new Array(5), that creates an array that contains a 5. Instead, you should do var a = []; a.length = 5;

Resources