Html.BeginForm no longer creating action in OrchardCMS - asp.net-mvc

I have recently rebuild a module DLL for an Orchard CMS project and one of the pages is not longer rendering form actions using BeginFormAntiForgeryPost.
The .cshtml file is:
#using System;
#using Orchard.Mvc.Html;
#{
var eventId = (int) Model.EventId;
string price = (string)Model.Price;
Orchard.ContentManagement.ContentItem contentItem = Model.Item;
string currencies = (string)Model.Currencies;
var pricesArray = price.Split(new Char[]{';'});
var currenciesArray = currencies.Split(new Char[]{';'});
bool allowCurrencyChange = true;
if(pricesArray.Length!=currenciesArray.Length){
allowCurrencyChange = false;
}
price = pricesArray[0];
string currency = currenciesArray[0];
}
<div class="prices-container">
<div class="more-info-link">
<a class="btn" href="#Url.Content("~"+Url.ItemDisplayUrl(contentItem))">
More Information
</a>
</div>
<div class="prices-box">
#if(Convert.ToDecimal(price)>0){
<p class="price">#currency #String.Format("{0:0,0.00}",price) <br /><span style="font-size:13px;">+ VAT</span></p>
}
else{
<p class="price" style="text-indent:-99999px;">#currency #String.Format("{0:0,0.00}",price)</p>
}
#using (Html.BeginFormAntiForgeryPost(Url.Action("Add", "ShoppingCart", new { id = eventId, area = "Events" }))) {
if(Convert.ToDecimal(price)>0){
<input type="hidden" name="currency" value="#currency" />
<input type="hidden" name="price" value="#price" />
if(allowCurrencyChange){
for(int i=0; i<pricesArray.Length;i++){
<input type="hidden" name="#(currenciesArray[i])_price" value="#(pricesArray[i])" />
}
}
<button class="btn btn-success" type="submit">#T("register")</button>
}
else{
<a href="/oforms/Contact-Us" class="btn btn-success" >#T("enquire")</a>
}
}
</div>
</div>
The output before the rebuild was:
<div class="prices-container" shape-id="13">
<div class="more-info-link" shape-id="13">
<a class="btn" href="/identify-the-right-talent" shape-id="13">
More Information
</a>
</div>
<div class="prices-box" shape-id="13">
<p class="price" shape-id="13">GBP 1197.50 <br shape-id="13"><span style="font-size:13px;" shape-id="13">+ VAT</span></p>
<form action="/Events/ShoppingCart/Add/13817" method="post" shape-id="13"> <input type="hidden" name="currency" value="GBP" shape-id="13">
<input type="hidden" name="price" value="1197.50" shape-id="13">
<input type="hidden" name="GBP_price" value="1197.50" shape-id="13">
<button class="btn btn-success" type="submit" shape-id="13">register</button>
<input name="__RequestVerificationToken" type="hidden" value="w10QfGWfU3Y2UNIWRVXtsqUxcSS/OX4GxWCAsdaWDMHV15LqkMpDcqQFYJ1lpbf7ZlNTP5ckVrWFtatRh2poJBTE9NxlXQRua8CNuXgVGtGnSr3lpWpt2KeAwNNhsvmZIiSSSZOuhwbXD08K7+H2fSkrFUAOKVX+eTarLBWdjg8jySGV+Q82oA37NMEBZrQXOWkq4TjEusC5ILqptA1fLZOR8qu0xuPlWrMf4Dli2kw=" shape-id="13">
</form>
</div>
</div>
And after rebuilding the module the FORM ACTION is no longer output:
<div class="prices-container" shape-id="13">
<div class="more-info-link" shape-id="13">
<a class="btn" href="/identify-the-right-talent" shape-id="13">
More Information
</a>
</div>
<div class="prices-box" shape-id="13">
<p class="price" shape-id="13">GBP 1197.50 <br shape-id="13"><span style="font-size:13px;" shape-id="13">+ VAT</span></p>
<form action="" method="post" shape-id="13">
<input type="hidden" name="currency" value="GBP" shape-id="13">
<input type="hidden" name="price" value="1197.50" shape-id="13">
<input type="hidden" name="GBP_price" value="1197.50" shape-id="13">
<button class="btn btn-success" type="submit" shape-id="13">register</button>
<input name="__RequestVerificationToken" type="hidden" value="LcZyoXchQ7IjEJJvxoFQzAYNVOk1ybC7KB/GzXkYdlE5n1zIy6fg3Dod8twQDLxA/cYvBwYfXYDWbNSq81dsq4UTSxevK1vXJxWGAWKOlt0dmt3si5RKYJbIXEplIScSoEBtr5Jaq95YsCe4jpdMe3QroYF5NGj9P8BhPKWbucHJiLyBJULc6ktYuRL0BFQk+oE9AaaYUUv6hyh20T/XTlPjl9uxalvJMTCIiDtSlZQ=" shape-id="13">
</form>
</div>
</div>
Why would the BeginFormAntiForgeryPost and/or Url.Action no longer output the action URL?

Related

rails amp form error request and response access-control-allow-origin

i'm using rails amp and setting my amp route for contact form
<form id='contactusform' method="POST" class="p2" action-xhr = "<%= addquery_path %>" custom-validation-reporting="as-you-go" target="_top">
<%= hidden_field_tag :authenticity_token, form_authenticity_token -%>
<div class="form-row">
<div class="inline-form">
<label class="inline-label">
<input type="text" id="as-you-go-name" pattern="p{L}+\s\p{L}+" class="inline-label-input input-item" name='name' value="" required />
<span class="inline-label-label">Name</span>
</label>
<div class="validation-blk">
<span visible-when-invalid="valueMissing" validation-for="as-you-go-name">Please enter your first name</span>
<span visible-when-invalid="patternMismatch" validation-for="as-you-go-name">Please enter characters only</span>
</div>
</div>
</div>
<div class="form-row">
<div class="inline-form">
<label class="inline-label">
<input type="email" id="as-you-go-email" class="inline-label-input input-item" value="" name='email' required />
<span class="inline-label-label">Email</span>
</label>
<span visible-when-invalid="valueMissing" validation-for="as-you-go-email">Please enter your email address</span>
<span visible-when-invalid="typeMismatch" validation-for="as-you-go-email"></span>
</div>
</div>
<div class="form-row">
<div class="inline-form">
<label class="inline-label">
<input type="number" id="phone-number" name='phone' class="inline-label-input input-item" value="" required />
<span class="inline-label-label">contatct number</span>
</label>
<span visible-when-invalid="valueMissing" validation-for="phone-number">Please enter your phone number</span>
</div>
</div>
<div class="form-row">
<div class="inline-form">
<label class="inline-label">
<input type="text" id="Cityname" name='city' pattern="\w+\s\w+" class="inline-label-input input-item" value="" required />
<span class="inline-label-label">City</span>
</label>
<span visible-when-invalid="valueMissing" validation-for="Cityname">Please enter your City</span>
</div>
</div>
<div class="form-row">
<div class="inline-form">
<label class="inline-label">
<input type="text" id="Statename" pattern="\w+\s\w+" class="inline-label-input input-item" name='state 'value="" required />
<span class="inline-label-label">State</span>
</label>
<span visible-when-invalid="valueMissing" validation-for="Statename">Please enter your State</span>
</div>
</div>
<div class="form-row">
<div class="inline-form">
<label class="inline-label">
<input type="text" id="Country" pattern="\w+\s\w+" class="inline-label-input input-item" name='country' value="" required />
<span class="inline-label-label">Country</span>
</label>
<span visible-when-invalid="valueMissing" validation-for="Country">Please enter your Country</span>
</div>
</div>
<div class="form-row">
<div class="inline-form selectionbox">
<label class="inline-label">
<select class="select-box custom-select" required name="eventtype"
id="eventtype">
<option value="">QUERY TYPE</option>
<% #app_config.event_type.split('|').each do |event_name,index| %>
<option value="<%= event_name %>"><%= event_name %></option>
<% end %>
</select>
</label>
<span visible-when-invalid="valueMissing" validation-for="eventtype">selectoption message appears like this</span>
</div>
</div>
<div class="form-row">
<div class="ampstart-input inline-block relative">
<textarea name="message" id="message" class="block" rows="5" cols="50" required placeholder="your message"></textarea>
<!-- <label class="textarea-ab" aria-hidden="true">
Your message
</label> -->
<span visible-when-invalid="valueMissing" validation-for="message"></span>
</div>
</div>
<div class="button button-common">
<input type="submit" value="OK" class="ampstart-btn caps">
</div>
<!-- social icons -->
<div submit-success>
<template type="amp-mustache">
Subscription successful!
</template>
</div>
<div submit-error>
<template type="amp-mustache">
Subscription failed!
</template>
</div>
</form>
And my controller saves the form in my database, but the browser throws an error.
def addquery
#contact = Lead.new
#contact.name = params[:name]
#contact.email = params[:email]
#contact.phone = params[:phone]
#contact.city = params[:city]
#contact.state = params[:state]
#contact.country = params[:country]
#contact.enquiry_type = params[:eventtype]
#contact.message = params[:message]
#contact.save
end
when i try to submit my AMP form it showing
amp form error request must have access-control-allow-origin
in my browser console.
as well as the
response must have access-control-allow-origin
Set access-control-allow-origin: <your domain> as a response header in the form handler in rails.
Example, if you are running on localhost set form response header as access-control-allow-origin: http://localhost:3000

self._NgForm_14_3.context is not a function

My Code:
<form role="form" #login="ngForm" (ngSubmit)="onSubmit(login.form)">
<div class="form-group">
<label class="control-label" for="adviserUsername">Username</label>
<input class="form-control" [(ngModel)]="adviserUsername" #username="ngModel" placeholder="Enter Username" type="text" name="adviserUsername"
required>
<div *ngIf="username.touched && username.errors">
<div class="alert alert-danger" *ngIf="username.errors.required">Username is required</div>
</div>
</div>
<div class="form-group">
<label class="control-label" for="password">Password</label>
<input class="form-control" [(ngModel)]="passwordText" #password="ngModel" id="password" name="password" placeholder="Password"
type="password" required>
</div>
<div class="alert alert-danger" *ngIf="password.touched && password.errors">Password is required</div>
<button type="submit" class="btn btn-block btn-lg btn-primary" (click)="login()" [disabled]="!login.valid">Login</button>
</form>
Error which I am getting is
self._NgForm_14_3.context is not a function
Here's a Snapshot
The Solution is simple
I was using a click event on the button click - which was using login() - this was double reference and created a problem ...
Code:
Line Fixed >>
<button type="submit" class="btn btn-block btn-lg btn-primary" [disabled]="!login.valid">Login</button>

Best way to prevent HTML Code in Textbox MVC Razor View

I have following code on my view.
This HTML code is used for search in website.
This view is not strongly typed view, so I can apply use DataAnnotation through model.
What is best view to validate that, this textbox should accept only alpha numeric characters?
HTML
<form action="Search" method="post" >
<div class="col-md-8">
<input type="text" name="name" placeholder="search" class="fullwidth" onkeypress="return BlockingHtml(this,event);" />
</div>
<div class="col-md-4">
<input type="submit" title="Search" value="Search" />
</div>
</form>
Javascript
function BlockingHtml(txt) {
txt.value = txt.value.replace(/[^a-zA-Z 0-9\n\r.]+/g, '');
}
Model:-
[StringLength(100)]
[Display(Description = "Name")]
[RegularExpression("(/[^a-zA-Z 0-9\n\r.]+/g", ErrorMessage = "Enter only alphabets and numbers of Name")]
public string Name{ get; set; }
Updated:-
View:-
<form action="Search" method="post" >
<div class="col-md-8">
<input type="text" name="name" id="txt" placeholder="search" class="fullwidth" onkeypress="BlockingHtml(this);" />
</div>
<div class="col-md-4">
<input type="submit" title="Search" value="Search" />
</div>
</form>
function BlockingHtml(txt) {
txt.value = txt.value.replace(/[^a-zA-Z 0-9\n\r.]+/g, '');
}
<form action="Search" method="post" >
<div class="col-md-8">
<input type="text" name="name" placeholder="search" class="fullwidth" onblur="return BlockingHtml(this,event);" />
</div>
<div class="col-md-4">
<input type="submit" title="Search" value="Search" />
</div>
</form>
Changed event onkeypress to onblur.

File upload using AngularJS and Rails

I have a model BOOK that will insert the book details through angularjs controller
Here is my view:
<h1 align="center">Books</h1>
<div ng-controller="BooksCtrl" class="container">
<div class="row-fluid">
<div class="col-md-6">
<form ng-submit="addBook()" class="loginform cf">
<input type="text" ng-model="newBook.title" placeholder="Title of the Book" required>
<input type="text" ng-model="newBook.isbn" placeholder="ISBN Number of Book" required>
<input type="file" ng-model="newBook.book_link">
<input type="text" ng-model="newBook.edition" placeholder="Edition of the book" required>
<input type="text" ng-model="newBook.publication_id" placeholder="Select the publication ID" required>
<input type="submit" value="Add Book">
</form>
<div ng-show="editorEnabled" class="loginform cf">
<form ng-submit="update()">
<input type=text ng-model="editableBook.title" ng-show="editorEnabled" required>
<input type=text ng-model="editableBook.body" ng-show="editorEnabled" required>
<input type="submit" value="Update" class='btn'>
close
</form>
</div>
<div ng-show="selectedBook" class="loginform cf">
<h2>{{selectedBook.title}}</h2>
<p>{{selectedBook.body}}</p>
</div>
</div>
<div class="col-md-6">
<ul style="list-style-type: none;">
<li ng-repeat="book in books" class="loginform cf" >
<div>
<div>{{book.title}}</div>
<a href="">
<img src="{{book.book_link.thumb.url}}"/>
</a>
<button href="#" ng-click="showBook(book)" class="btn">Show</button>
<button href="#" ng-click="enableEditor(book)" class="btn">edit</button>
<br>
</div>
</li>
</ul>
</div>
</div>
</div>
My angularjs Controller function is:
book = Book.save($scope.newBook, function(data,headers) {
console.log(book);
$scope.books.push(book);
}, function(data,headers) {
// do the error case
console.log(data);
if (data.status == 422)
{
alert("validation is failed book should be unique");
}
});
The problem is that it is storing all the details except the book pdf upload. It is not passing even the name. How can I solve this? Any Suggestions would be appreciated.

Content Collapsible jquery mobile

I have a problem with jQuery Mobile 1.1.0 accordion ( http://jquerymobile.com/test/docs/content/content-collapsible.html )
I have a page with more accordion, and when I press to open / close the section brings me back to the top of the page.
I have already set:
ajaxEnabled: false;
hashListeningEnabled: false;
linkBindingEnabled: false;
this is my code:
<!-- anagrafica -->
<div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="c">
<h3>Scheda cliente</h3>
<!-- Dati azienda -->
<div data-role="collapsible" data-collapsed="true" data-content-theme="c" class="grid-scheda">
<h3>Anagrafica</h3>
<form id="dati-azienda">
<div data-role="fieldcontain">
<label for="ragionesociale">Ragione Sociale:</label>
<input type="text" name="ragionesociale" id="ragionesociale" class="required fullsize" />
</div>
<div data-role="fieldcontain">
<label for="indirizzo">Indirizzo:</label>
<input type="text" name="indirizzo" id="indirizzo" class="fullsize" />
</div>
<div data-role="fieldcontain">
<label for="localita">Località:</label>
<input type="text" name="localita" id="localita" class="large" />
<input type="text" name="cap" id="cap" class="small" placeholder="CAP" />
</div>
<div data-role="fieldcontain">
<label for="pi">Partita IVA:</label>
<input type="number" name="pi" id="pi" class="fullsize" />
</div>
<div data-role="fieldcontain">
<label for="fisso">Fisso:</label>
<input type="number" name="fisso" id="fisso" class="medium" />
<input type="number" name="fax" id="fax" class="medium" placeholder="Fax" />
</div>
<div data-role="fieldcontain">
<label for="mobile">Mobile:</label>
<input type="number" name="mobile" id="mobile" class="fullsize" />
</div>
<div data-role="fieldcontain">
<label for="mail">Mail:</label>
<input type="text" name="mail" id="mail" class="fullsize" />
</div>
<!--
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<legend>Altre sedi:</legend>
<input type="checkbox" name="checkbox-0" style="margin-top:0px;" id="checkbox-mini-0" data-mini="true" />
<label for="checkbox-mini-0">Si</label>
</fieldset>
</div>
-->
<fieldset class="ui-grid-a">
<label> </label>
<div class="ui-block-b"><button rel="dati-azienda" type="submit" class="submit submitBTN" data-theme="b">Salva</button></div>
</fieldset>
</form>
</div><!-- /Dati Azienda -->
<!-- Dati Referente -->
<div data-role="collapsible" data-content-theme="c" class="grid-scheda">
<h3>Dati Referente</h3>
<form id="dati-referente">
<div data-role="fieldcontain">
<label for="cognome">Referente:</label>
<input type="text" name="cognome" id="cognome" class="small2" placeholder="Cognome" />
<input type="text" name="nome" id="nome" class="small2" placeholder="Nome"/>
<input type="text" name="dt_nascita" id="dt_nascita" class="small2" placeholder="Data nascita"/>
</div>
<div data-role="fieldcontain">
<label for="posizione">Posizione:</label>
<input type="text" name="posizione" id="posizione" class="medium" />
<input type="text" name="reperibilita" id="reperibilita" class="medium" placeholder="Reperibilità" />
</div>
<div data-role="fieldcontain">
<label for="mobile">Mobile:</label>
<input type="number" name="mobile" id="mobile" class="medium" />
<input type="number" name="fisso" id="fisso" class="medium" placeholder="Fisso" />
</div>
<div data-role="fieldcontain">
<label for="mail">Mail:</label>
<input type="text" name="mail" id="mail" class="fullsize" />
</div>
<div data-role="fieldcontain">
<label for="referente2">Referente alternativo:</label>
<input type="text" name="referente2" id="referente2" class="fullsize" />
</div>
<fieldset class="ui-grid-a">
<label> </label>
<div class="ui-block-b"><button rel="dati-referente" type="submit" class="submit submitBTN" data-theme="b">Salva</button></div>
</fieldset>
</form>
</div><!-- /Dati referente -->
<!-- caratteristiche -->
<div data-role="collapsible" data-content-theme="c" class="grid-scheda">
<h3>Caratteristiche</h3>
<div data-role="fieldcontain">
<label for="x">Consistenza attiva:</label>
<input type="text" name="x" id="x" class="small" />
</div>
</div><!-- /caratteristiche -->
<!-- registrazione -->
<div data-role="collapsible" data-content-theme="c" class="grid-scheda">
<h3>Registrazione 190</h3>
<form id="registrazione">
<div data-role="fieldcontain">
<label for="userid">User ID:</label>
<input type="text" name="userid" id="userid" class="small2" />
<input type="text" name="passw" id="passw" class="small2" placeholder="Password" />
<input type="date" name="dt_registrazione" id="dt_registrazione" class="small2" />
</div>
<?php for($i=1;$i<=2;$i++) { ?>
<div data-role="fieldcontain">
<label for="analisi_ft_num">Analisi Fattura:</label>
<input type="text" name="analisi_ft_num[]" id="analisi_ft_num" class="medium" placeholder="Nr. Fattura" />
<input type="date" name="dt_doc[]" class="medium" />
</div>
<?php } ?>
<div data-role="fieldcontain">
<label for="codice_cliente">Codice Cliente:</label>
<input type="text" name="codice_cliente" id="codice_cliente" class="medium" />
<input type="text" name="ciclo_fatturazione" id="ciclo_fatturazione" class="medium" placeholder="Ciclo Fatturazione" />
</div>
<fieldset class="ui-grid-a">
<label> </label>
<div class="ui-block-b"><button rel="registrazione" type="submit" class="submit submitBTN" data-theme="b">Salva</button></div>
</fieldset>
</form>
</div><!-- /registrazione -->
</div>
<!-- /anagrafica -->
Thanks in advice
It is not very clear as to what exactly the interface is supposed to look like. However, please look at the documentation: http://jquerymobile.com/demos/1.1.0/docs/content/content-collapsible-set.html
The link you pasted is for a test demo, but the syntax seem to have changed since then.

Resources