How do I send user inputs (HTML) to an array in Angular? - html

How do I get the inputs from this form to go into an array in angular?
<form>
<tr>
<td class="Meal-form">
<input type="date" ng-model="date" placeholder="select" required></td>
<td>
<select ng-model="meal" ng-options="meals.name for meals in mealTypes">
<option value="" disabled selected>Select</option>
</select>
</td>
<td><input type="text" ng-model="about" placeholder="What did you eat" required></td>
<td>
<select ng-model= "feel" ng-options="feeling.name for feeling in feels">
<option value="" disabled selected>Select</option>
</select>
</td>
<td><input type="submit" id="submit" value="Submit Content"></td>
</tr>
</form>
I get how to pull the information from angular to HTML, but not how to get the HTML to angular.

You need to create your model in controller, and save function
$scope.model = {
date: '',
meal: '',
about:'',
feel: ''
};
$scope.save = function()
{
alert($scope.model.date);
alert($scope.model.meal);
$scope.yourarray.push($scope.model);
}
You Html need to change
<form>
<tr>
<td class="Meal-form">
<input type="date" ng-model="model.date" placeholder="select" required></td>
<td>
<select ng-model="model.meal" ng-options="meals.name for meals in mealTypes">
<option value="" disabled selected>Select</option>
</select>
</td>
<td><input type="text" ng-model="model.about" placeholder="What did you eat" required></td>
<td>
<select ng-model= "model.feel" ng-options="feeling.name for feeling in feels">
<option value="" disabled selected>Select</option>
</select>
</td>
<td><input type="buttton" ng-click="save()" id="submit" value="Submit Content"></td>
</tr>
</form>
Note the ng-bind, it should be like this ng-model="model.date"

Using ng-model you create a dual-binding relationship between your view (the HTML) and your model (the JS). That is to say when the user types in to your form, you can then do
console.log($scope.date)
to print the date they entered.

Related

Form submit doesn't work at all inside foreach loop

The button doesn't do anything at all. It works if I make a form with submit inside each <td tag, but obviously I don't wanna do that since then you can't read all the values.
I just wanna have 1 submit button, for some reason that breaks it. facepalm
Came across few similar topics but none of them quite had any solution I was looking for.
html:
<table class="table table-hover">
#foreach ($query as $x)
<tr class="table-dark">
<form method="post" action="{{ action('Controller#admin_changeinfo') }}" enctype="multipart/form-data">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<th scope="row">User#{{$x->user_id}}</th>
<td>{{$x->name}}</td>
<td>
<input name="target" type="hidden" value="{{$x->user_id}}"/>
<input name="name" type="hidden" value="{{$x->name}}"/>
<input name="email" type="text" class="form-control"
id="admin_place_em" value="{{$x->email}}" placeholder="{{$x->email}}">
</td>
<td>
<select name="role" class="custom-select" id="admin_role_change">
<option selected="" value={{$x->role}}>{{$role_ar[$x->role]}}</option>
<option value="1" class="admin_role_opt">Value 1</option>
<option value="2" class="admin_role_opt">Value 2</option>
<option value="0" class="admin_role_opt">Value 0</option>
<option value="3" class="admin_role_opt">Value 3</option>
</select>
</td>
<td>
<input name="" type="submit" value="Update" href="/admin" class="btn btn-default">
</td>
</form>
</tr>
#endforeach
{{$query->links()}}
</table>
And here is the route if that's any help:
Route::post('/admin','Controller#admin_changeinfo');
--
EDIT:
Apparently, you can't have a Form inside a table .
Solution: Put the whole table inside the form. Create a button with an unique value, make the other fields unique as well:
<button name="submit" type="submit" value={{$x->user_id}} href="/admin" class="btn btn-default">
Update
</button>
In your controller:
$pressed = $request->submit;
$this -> validate($request, [
'email'.$pressed => 'required',
'role'.$pressed => 'required|in:1,2,3,0'
]);
$name = $request -> input('name'. $pressed);
$target = $request -> input('target'. $pressed);
return 'submit called: '.$name.' '.$target;
Fixed version:
<form method="post" action="{{ action('Controller#admin_changeinfo') }}" enctype="multipart/form-data">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
<table class="table table-hover">
#foreach ($query as $x)
<tr class="table-dark">
<th scope="row">User#{{$x->user_id}}</th>
<td>{{$x->name}}</td>
<td>
<input name="target{{$x->user_id}}" type="hidden" value="{{$x->user_id}}"/>
<input name="name{{$x->user_id}}" type="hidden" value="{{$x->name}}"/>
<input name="email{{$x->user_id}}" type="text" class="form-control"
id="admin_place_em" value="{{$x->email}}" placeholder="{{$x->email}}"/>
</td>
<td>
<select name="role{{$x->user_id}}" class="custom-select" id="admin_role_change">
<option selected="" value={{$x->role}}>{{$role_ar[$x->role]}}</option>
<option value="1" class="admin_role_opt">Value 1</option>
<option value="2" class="admin_role_opt">Value 2</option>
<option value="0" class="admin_role_opt">Value 0</option>
<option value="3" class="admin_role_opt">Value 3</option>
</select>
</td>
<td>
<button name="submit" type="submit" value={{$x->user_id}} href="/admin" class="btn btn-default">
Update
</button>
</td>
</tr>
#endforeach
{{$query->links()}}
</table>
</form>
1- change this
<input name="" type="submit" value="Update" href="/admin" class="btn btn-default">
to this
<button type="submit">Update</button>
2- change this
Route::post('/admin','Controller#admin_changeinfo');
to this:
Route::post('/admin', ['as' => 'admin.changeinfo',
'uses' => 'Controller#admin_changeinfo'] );
3- change this:
<form method="post" action="{{ action('Controller#admin_changeinfo') }}" enctype="multipart/form-data">
to this:
{!! Form::open(['route' => ['admin.changeinfo'],
'method' => 'post',
'enctype' => 'multipart/form-data']) !!}

easy and quick Simple form edit please

The forms which l have here, have required files to be entered before the submit button. All l need it for the top 'title' list to be required='true'. I know how to do it for each and every of the text forms but unsure how to position the code for an options choice list.
Cheers guys.
Please take a look at the jsfiddle l have created for this:
http://jsfiddle.net/New_to_Websites/5A4vS/#run
Code:
<script language="javascript">
var sa_sent_text = 'Thank you for contacting us. We will get back to you soon.';
function sendme() {
alert(sa_sent_text);
document.getElementById("name").value = "";
document.getElementById("message").value = "";
document.getElementById("subject").value = "";
document.getElementById("email").value = "";
return false;
}
</script>
<div id="sa_contactdiv">
<form name=sa_htmlform style="margin:0px" onsubmit="return sendme();">
<table>
<tr>
<td>Title:
<br>
<select name="title" size="1">
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Miss">Miss</option>
<option value="Ms.">Ms.</option>
<option value="Dr.">Dr.</option>
<option value="Prof.">Prof.</option>
<option value="Other">Other</option>
</select>
</td>
</tr>
<tr>
<td>Name:
<br>
<input type="text" id="name" name="name" />
</td>
</tr>
<tr>
<td>E-mail Address: <span style="color:#D70000">*</span>
<br>
<input type="text" id="email" name="email" required="true" />
</td>
</tr>
<tr>
<td>Subject: <span style="color:#D70000">*</span>
<br>
<input type="text" id="subject" name="subject" required="true" />
</td>
</tr>
<tr>
<td>Message: <span style="color:#D70000">*</span>
<br>
<textarea name="message" id="message" cols="42" rows="9" required="true"> </textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Send Message" style="font-weight:bold">
</td>
</tr>
</table>
</form>
</div>
This should work:
<select name="title" size="1" required aria-required=”true”>
<option value="">Please Choose</option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Miss">Miss</option>
<option value="Ms.">Ms.</option>
<option value="Dr.">Dr.</option>
<option value="Prof.">Prof.</option>
<option value="Other">Other</option>
</select>
If you have an option with a empty value as default, the required attribute works.
Working Fiddle
The required attribute is a boolean attribute. When specified, the user will be required to select a value before submitting the form.
If a select element has a required attribute specified, does not have a multiple attribute specified, and has a display size of 1; and if the value of the first option element in the select element's list of options (if any) is the empty string, and that option element's parent node is the select element (and not an optgroup element), then that option is the select element's placeholder label option.
Quoted from http://dev.w3.org/html5/spec-author-view/the-select-element.html
Try this
<td>Title:<span style="color:#D70000">*</span>
<br>
<select name="title" size="1" required="true">
<option value=""></option>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Miss">Miss</option>
<option value="Ms.">Ms.</option>
<option value="Dr.">Dr.</option>
<option value="Prof.">Prof.</option>
<option value="Other">Other</option>
</select>

Some inputs not submitted

I have an HTML form but some of the inputs in it are not submitted, even though they are active. Live example at http://jsfiddle.net/hbw3/qzcTS/2/.
The form clearly contains a number of divs but only the inputs in one div are submitted. Why is this?
The HTML source:
<form accept-charset="UTF-8" action="whatever" id="map_form" method="post">
<table>
<tr>
<td>
<select id=1 name=col_1 class="column_select">
<option value="0">None</option>
<option value="1">id (integer)</option>
<option value="2">name (string)</option>
</select>
</td>
<td>
<select id=2 name=col_2 class="column_select">
<option value="0">None</option>
<option value="1">id (integer)</option>
<option value="2">name (string)</option>
</select>
</td>
</tr>
</table>
<div class="span4" id="default_values">
<label for='id' class='control-label'>id (integer)</label>
<input type='text' id='id' />
<label for='name' class='control-label'>name (string)</label>
<input type='text' id='name' />
</div>
<input name="commit" type="submit" value="Upload Table" />
</form>
<div id='result'></div>
The JS to display the submitted inputs:
$('form#map_form').submit(function () {
$('div#result').text($(this).serialize());
return false;
})
You're missing name attributes on the inputs in your last div. I tried adding some to your sample and that seems to have fixed it.

html field alignment

Good afternoon,
I am new to html. I have added html form fields into my application. The textfields are not aligned and they look really untidy. This is because i have field names like 'first tag' and 'second tag' which have a text field beside it. The text field for second tag appears more towards the left compared to the first. Is there a way i can align them without using a table? if i use a table, may i know how should i do it? i am sorry i cant upload any photos since i am a new user.
below is my html code.
Thank you for any help!
Cheers,
ZhengHong
<div class="rightsettings">
<form name="addsubject" action="html_form_action.asp" method="get">
<br>Subject: <input type="text" name="user" /></br>
<br>Number of tags<select name="addnoofsubject" id = "addnoofsubject" onchange="checktags()">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select></br>
<div id="addfirsttag">
<br>First Tag: <input type="text" name="tag1"/></br>
<div id = "addsecondtag" style="visibility:hidden">
<br>Second Tag: <input type="text" name="tag2"/></br>
</div>
<div id = "addthirdtag" style="visibility:hidden">
<br>Third Tag: <input type="text" name="tag3"/></br>
</div>
<div id = "addfourthtag" style="visibility:hidden">
<br>Fourth Tag: <input type="text" name="tag4"/></br>
</div>
<div id = "addfifthtag" style="visibility:hidden">
<br>Fifth Tag: <input type="text" name="tag5"/></br>
</div>
<br><input type="submit" value="Submit" /></br>
</form>
</div>
I recommend you to insert your forms into tables.
<div class="rightsettings">
<form name="addsubject" action="html_form_action.asp" method="get">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td>Subject:</td><td><input type="text" name="user" /></td></tr>
<tr><td>Number of tags::</td><td><select name="addnoofsubject" id = "addnoofsubject" onchange="checktags()">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select></td></tr>
<tr><td>First Tag:</td><td><div id="addfirsttag"><input type="text" name="tag1"/></div></td></tr>
<!-- all your tags like the one above -->
<tr><td colspan="2" align="center"><input type="submit" value="Submit" /></td></tr>
</table>
</form>
</div>
try this one
<table>
<tr style="visibility:hidden"><td>First tag :><td><input type="text" name="tag1"/></td></tr>
<tr style="visibility:hidden"><td>Second tag :><td><input type="text" name="tag2"/></td></tr>
<tr style="visibility:hidden"><td>Third tag :><td><input type="text" name="tag3"/> </td></tr>
<tr><td colspan="2" align="center"><input type="submit"></td></tr>
</table>
with a table
<table>
<tr><td>First Tag</td><td><input ... /></td></tr>
<tr><td>Second Tage</td><td><input ... /></td></tr>
...
</table>
with css
css part :
label
{
display: block;
width: 150px;
float: left;
}
html part :
<label for="tag1">First Tag:</label><input ... /><br />
<label for="tag2">Second Tag:</label><input ... /><br />

converting 2 html files into a single .vm file

I am making 2 different web application for smart phones, using jQuery mobile and webapp-net.
so far I have the following codes: (its just a part of these codes, since I can not put the whole thing here)
<div data-role="collapsible" data-collapsed="true">
<h3>Eenmalige machtiging </h3>
<div data-role="fieldcontain" >
<form >
<input type="number" pattern="[0-9]*" id="anum" maxlength="9" placeholder="Account Number" autocomplete="off" onBlur="isValidAnum()" onFocus="emptyAnum('anum')"/>
<input type="text" id="bname" placeholder="Beneficiary Name" autocomplete="off" onBlur="isValidBname()" onFocus="emptyBname('bname')"/>
<table>
<tr><td>
Select Your Bank
</td>
<td>
<select name="select-bank" id="select-bank" class="select-bank" data-inline = "true" >
<option value="abn">ABN Amro</option>
<option value="rabo">Rabo Bank</option>
<option value="ing">ING Bank</option>
<option value="overige"> --Overig--</option>
</select>
</td>
</tr>
</table>
<table>
<tr>
<td>I Agree </td>
<td><input type="checkbox" class = "checkbox" name="cbox" id="cbox2"/></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<br/>
<a data-role = "button" type="submit" data-icon = "check" data-theme="b">Pay</a>
</form>
</div>
</div>
</div>
</div>
and:
<button class="form_header" id="last_method"><img src="appimages/directdebit_NL.png" align="middle" /> Eenmalige Machtiging</button>
<div class="form_body">
<fieldset>
<ul>
<li>
<input type="number" pattern="[0-9]*" id="anum" maxlength="9" placeholder="Account Number" autocomplete="off" onBlur="isValidAnum()" onFocus="emptyAnum('anum')"/>
</li>
<li>
<input type="text" id="bname" placeholder="Beneficiary Name" autocomplete="off" onBlur="isValidBname()" onFocus="emptyBname('bname')"/>
</li>
<li>
<table>
<tr><td>
Select Your Bank
</td>
<td>
<select name="select-bank" id="select-bank" class="select-bank" data-inline = "true" >
<option value="abn">ABN Amro</option>
<option value="rabo">Rabo Bank</option>
<option value="ing">ING Bank</option>
<option value="overige"> --Overig--</option>
</select>
</td>
</tr>
</table>
</li>
<li>
<table>
<tr>
<td>I Agree </td>
<td><input type="checkbox" class = "checkbox" name="cbox" id="cbox2" /></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<input type="submit" value="Pay" class="pay_button"/>
</li>
</ul>
</fieldset>
</div>
</div>
</div>
Now I have to create a .vm file using these two codes, in order to do that I need to see what are the difference in html between these two. I tried to make it look alike each other as much as I could, I dont think I can change them any more. I was also trying to work with their css but I didnt change anything.
my question is there a possible way to put these html in a single .vm file??? if you know how to do it please help me, also if you need more info just ask me.
Are you talking about file diff? Where you check the differences in two files and merge them?
There is winmerge http://winmerge.org/
There is examdiff. Do a google search for file comparison or file diff