Passing AngularJS variable through form input field does not work - forms

I have an iFrame that has content on a different domain, that I also control. I like to pass confidential data from the parent to the iFrame. Therefore, I do not want to pass it via query string or URL. I like to pass it via Form hidden input fields. It works if the values of the fields are text. However, it does not work if I use AngularJS variables as values for the fields.
Below is my code.
{{session.user.user_ID}} and {{i18n.domain}} works in this HTML file and writes the correct values to the webpage.
<form id="form_frame" action="http://other.mydomain.com/forIframe.php" method="post" target="output_frame">
<input type="hidden" value="{{session.user.user_ID}}" name="id" />
<input type="hidden" value="{{i18n.domain}}" name="domain" />
</form>
<iframe name="output_frame" width="400" height="400">
</iframe>
<script language="JavaScript" type="text/javascript">
document.getElementById("form_frame").submit(); // automatically submit the form
</script>
I have this in my forIframe.php file, which is the file that writes the content for the iFrame:
echo 'user ID is: '.$_POST['id'];
However, the above writes this:
user ID is: {{session.user.user_ID}}
Why doesn't this AngularJS variable parse correctly into the value attribute of the input field? How do I pass the values in {{session.user.user_ID}} and {{i18n.domain}} securely to my PHP file in my iFrame?

Elements inside the iFrame do not inherit the scope of the parent. You best bet is to use messaging i.e. $broadcast and $on : http://plnkr.co/edit/Osa5MNKiJKzsi7wAUXgM?p=preview

Related

how to get the form name of current input text onchange in angular 2

I have scenario where I am changing the input text, i have multiple forms and one input within each form so i want to get the current form name whose input i am changing. how to do this in angular 2??
Below is my code for child component
<form #form1="NgForm" novalidate>
<input id="phoneNumber" type="text" placeholder="phoneNumber" class="validate"/>
</form>
<form #form2="NgForm" novalidate>
<input id="mobileNumber" type="text" placeholder="mobileNumber" class="validate"/>
</form>
Now suppose i am adding mobile number i want its form name. How to do this angular 2?? This is i want to access in parent component I am accessing the child component form using #ViewChildren and i am able to access the form manually but i want access dynamically with respect to the input i am accessing ..
In Angular you have two choices use dynamic forms or template driven forms,
your choice is dynamic forms using #form1="NgForm"
Angular dynamic-form
In your code you forgot the '[formControlName]' directive on the inputs, when you have those you can access the form from your component code like:
Component:
this.form1.valueChanges.subscribe(data => console.log('Form changes', data));
HTML:
<form #form2="NgForm" novalidate>
<input [formControlName]="mobileNumber" type="text" placeholder="mobileNumber" class="validate"/>
</form>
I am able to get the current form valid invalid in parent form by passing index as input to child form and emitting the same in parent form...

How to parse html forms in the Go Iris framework?

Sorry if this question is a bit basic, but how can you parse form inputs in the Go Iris framework?
Here is the form I am using
<form action="/" method="post">
Username:<input type="text" name="username">
Password:<input type="password" name="password">
<input type="submit" value="Login">
</form>
here is the route and the controller respectively
iris.Post("/", TestController)
func TestController(c *iris.Context){
username := c.Form.Get("username")//Doesn't work
password := c.Form.Get("password")//Doesn't work
}
how do I retrieve the values in the Post request after the form has been submitted, Thanks
Based off an example on the iris github page you could try c.PostValue("Username"). The code you have may also work but I think you need to capitalize the variable names. In the html template you can see the name value is lowercased, however your context is more likely going off those the variable names to the left of the actual html like Username.

How can I submit a AngularJS model the old-fashioned way?

In my Angular app I'm having a form bound to a model. The form does not have fields for all model properties.
When the user hits the submit button I want to post the form the traditional way, not as AJAX request (I have to deal with an already existing server side script).
That basically works if I add a action to the form. But it obviously only submits the form with its present fields as it is, not the whole model just like it's done when using the $http service.
And additionally it does not create name attributes.
How could I submit the form the old-school way with the full model data? Do I have to create the missing form fields on my own or is there a way to let Angular do that for me?
<script>
angular.module('foobar', []).controller('ContentCtrl', ['$scope', function($scope) {
$scope.content = {
'title': 'Foo',
'subtitle': 'Bar',
'text': 'desc' // this field is missing in the form itself and therefore is not submitted
};
}]);
</script>
<form action="http://postcatcher.in/catchers/521c6510429f840200000169" method="post" ng-controller="ContentCtrl">
<input type="text" name="est" ng-model="content.title" value="asdf">
<input type="text" ng-model="content.subtitle">
<button>submit</button>
see post result
</form>
Here's a plunker: http://plnkr.co/edit/5XYGH9hTe7cpchSFWbTK
Angular doesn't do anything special when you have a form with an action defined. It's pure html form submission with exactly the fields that are defined.
Normally you would use:
<input type="hidden" ng-model="content.desc">
but angular currently (1.2.0rc1) still doesn't support ng-model binding to hidden inputs.
The workaround is this:
<input type="text" name="text" ng-model="content.text" ng-hide="true">

add groovy code to grails input form

Is it possible to add groovy code to grails form?
I have a form:
<g:uploadForm controller="document" action="save" method="post">
<input type="file" name="dataFile" />
<input type="submit" id="addDocument" value="<g:message code=messages.document.save"/>">
</g:uploadForm>
I need to add code that puts the URL segments to the parameter value.
You're using a POST (because it's an upload and that's correct) method in your form, so you will not see the params in the URL. The params will get there (to the controller you redirect the request to), but won't show at the URL. In any case, you should go with hidden inputs in your form. Like:
<input type="hidden" id="foo" value=""/>
In your controller, you can get the parameters set in your input hidden fields simply by accessing the params map:
params.foo
Use hidden fields inside the form.

post variable with textarea

I think that if you assign a name attribute to an input type='text' that name becomes the post variable. How can you assign a post variable to am html textarea. i cant seem to get it working. Im just trying to take a user's imputed text from the textarea and put it into a mysql database. thanks
form:
<form action='index.php' method='POST'>
<textarea name='form'></textarea>
</form>
<?php $input=$_POST['form']; ?>