Keep input data after posting - razor-2

I have an issue with a long form I'm doing. If a user fills out the form, and validation is invalid, it erases everything in the form, and doesn't keep the data in the valid forms. How would I make it so it doesn't erase the data upon pressing submit?
#{
Layout = "~/Pages/_SiteLayout.cshtml";
var db = Database.Open("mtarplspd");
Validation.RequireField("TypeOfIncident", "Type of incident is required.");
Validation.RequireField("FirstName", "Firstname is required.");
Validation.RequireField("LastName", "Lastname is required.");
Validation.RequireField("Rank", "Rank is required.");
Validation.RequireField("Badge", "Badge is required.");
Validation.RequireField("SuspectFirstName", "Suspect firstname is required.");
Validation.RequireField("SuspectLastName", "Suspect lastname is required.");
Validation.RequireField("SuspectCharges", "Suspect charges is required.");
Validation.RequireField("Description", "Description of the incident is required.");
var typeOfIncident = "";
var firstName = "";
var lastName = "";
var rank = "";
var badge = "";
var suspectFirstName = "";
var suspectLastName = "";
var suspectAddress = "";
var suspectCharges = "";
var suspectVehicleModel = "";
var suspectVehiclePlates = "";
var suspectVehicleColor = "";
var officersInvolved = "";
var description = "";
var departmentsInvolved = "";
var firearmDischarged = "";
var typeOfFirearm = "";
var roundsFired = "";
var reason = "";
var userId = 0;
var dateTime = "";
var ErrorMessage = "";
if (IsPost) {
typeOfIncident = Request.Form["TypeOfIncident"];
firstName = Request.Form["FirstName"];
lastName = Request.Form["LastName"];
rank = Request.Form["Rank"];
badge = Request.Form["Badge"];
suspectFirstName = Request.Form["SuspectFirstName"];
suspectLastName = Request.Form["SuspectLastName"];
suspectAddress = Request.Form["SuspectAddress"];
suspectCharges = Request.Form["SuspectCharges"];
suspectVehicleModel = Request.Form["SuspectVehicleModel"];
suspectVehiclePlates = Request.Form["SuspectVehiclePlates"];
suspectVehicleColor = Request.Form["SuspectVehicleColor"];
officersInvolved = Request.Form["OfficersInvolved"];
description = Request.Unvalidated["Description"];
departmentsInvolved = Request.Form["DepartmentsInvolved"];
firearmDischarged = Request.Form["FirearmDischarged"];
typeOfFirearm = Request.Form["TypeOfFirearm"];
roundsFired = Request.Form["RoundsFired"];
reason = Request.Form["Reason"];
userId = WebSecurity.CurrentUserId;
dateTime = DateTime.Now.ToString("d MMM yyyy h:mm:ss");
if (ErrorMessage == "" && Validation.IsValid()) {
var insert = "INSERT INTO Reports (Type, FirstName, LastName, Rank, Badge, SuspectFirstName, SuspectLastName, SuspectAddress, SuspectCharges, SuspectVehicleModel, SuspectVehiclePlates, SuspectVehicleColor, OfficersInvolved, Description, DepartmentsInvolved, FirearmDischarged, TypeOfFirearm, RoundsFired, Reason, UserId, DateTime)" + "VALUES (#0, #1, #2, #3, #4, #5, #6, #7, #8, #9, #10, #11, #12, #13, #14, #15, #16, #17, #18, #19, #20)";
db.Execute(insert, typeOfIncident, firstName, lastName, rank, badge, suspectFirstName, suspectLastName, suspectAddress, suspectCharges, suspectVehicleModel, suspectVehiclePlates, suspectVehicleColor, officersInvolved, description, departmentsInvolved, firearmDischarged, typeOfFirearm, roundsFired, reason, userId, dateTime);
Response.Redirect("~/Pages/Reports/Incident/Default");
}
}
}

You need to restore the value for each form control, eg:
<input type="text" name="FirstName" value="#Request.Form["FirstName"]" />

Related

Trying to display name of users on support action bar

Please i am new to kotlin and i have been trying to retrive the fullname of my users in the data base after using getStringExtra so i can use each of them for the title of my support action bar but the value it returns an empty value.
val name = intent.getStringExtra("fullname")
val receiverUid = intent.getStringExtra("uid")
val senderUid = FirebaseAuth.getInstance().currentUser?.uid
mDbRef = FirebaseDatabase.getInstance().getReference()
senderRoom = receiverUid + senderUid
receiverRoom = senderUid + receiverUid
supportActionBar?.title = name
Here is how i am sending name and receiverUid to my database
sendButton.setOnClickListener{
val message = messageBox.text.toString()
val messageObject = Message(message, senderUid)
val name = name.toString()
val receiverUid = receiverUid.toString()
val chatlistObject = ModelChatList(name, message, receiverUid)
mDbRef.child("chats").child(senderRoom!!).child("messages").push()
.setValue(messageObject).addOnSuccessListener {
mDbRef.child("chats").child(receiverRoom!!).child("messages").push()
.setValue(messageObject).addOnSuccessListener {
mDbRef.child("Chatlist").push().setValue(chatlistObject)
}
}
messageBox.setText("")
But when i try to retrive my ModelChatlist object it returns only two values leaving out the receivername as shown in the ModelChatlist below
class ModelChatList {
private var receivername:String = ""
private var lastmessage:String = ""
private var uid:String = ""
constructor(){}
constructor(receivername: String, lastmessage:String, uid:String){
this.receivername = receivername
this.lastmessage = lastmessage
this.uid =uid
}
fun getReceivername(): String{
return receivername
}
fun setReceivername(receivername: String){
this.receivername= receivername
}
fun getUid(): String{
return uid
}
fun setUid(uid: String){
this.uid= uid
}
fun getLastmessage(): String{
return lastmessage
}
fun setLastmessage(lastmessage: String){
this.lastmessage= lastmessage
}
}
In case you are wondering, "fullname" is in my database as the name the users enter when they sign up. Thank You

loop through sheet for unmarked value to update Google contacts

I've got a working script that grabs the last row of a Google sheet and pushes the info into Google contacts.
var ss = SpreadsheetApp.getActiveSheet(); //var emailRow = ss.getRange('F2:F').getValues();
var emailRowNum = ss.getLastRow(); //var emailRowNum = emailRow.filter(String).length + 1;
function email() {
var emailNew = ss.getRange(emailRowNum,6).getValue(); //var emailNew = ss.getRange("F"+emailRowNum).getValues();
return emailNew;}
function givenName() {
var fname = ss.getRange(emailRowNum,4).getValue();
return fname;}
function lastName() {
var lname = ss.getRange(emailRowNum,5).getValue();
return lname;}
function loc() {
var street = ss.getRange(emailRowNum,8).getValue();
var city = ss.getRange(emailRowNum,9).getValue();
return street + " " + city;}
function phone() {
var phone = ss.getRange(emailRowNum,7).getValue();
return phone;}
function notes() {
var date = ss.getRange(emailRowNum,1).getValue();
var work = ss.getRange(emailRowNum,2).getValue();
var photo = ss.getRange(emailRowNum,3).getValue();
var site = ss.getRange(emailRowNum,12).getValue();
var find = ss.getRange(emailRowNum,10).getValue();
var referrer = ss.getRange(emailRowNum,11).getValue();
return (date + "\n\n" + work + "\n\n" + photo + "\n\n" + site + "\n\n" + find + " " + referrer + "\n\n-- eom --\n\n");}
function create() {
var fname = givenName();
var lname = lastName();
var contact = ContactsApp.createContact(fname, lname, email());
var group = ContactsApp.getContactGroup('emf');
group.addContact(contact);
var contacts = ContactsApp.getContactsByName(fname + ' ' + lname);
var setaddress = contacts[0].addAddress(ContactsApp.Field.HOME_ADDRESS,loc());
var setphone = contacts[0].addPhone(ContactsApp.Field.MAIN_PHONE,phone());
for (var i in contacts) {
contacts[i].setNotes(notes());
}
}
I'd like to modify it so that instead of grabbing the last row, it checks a column for a (not) value. If value is not found, then update Google contacts with that row's information.
Currently, I'm getting a 'Range not found' error ...
function info(){
var ss = SpreadsheetApp.getActiveSheet();
var data = ss.getRange("N1:N").getValues();
for(var n=0;n<data.length;n++){
if(data[n-1] != 'done'){
var email = ss.getRange("F"+n).getValue(); // Range not found error
var fname = ss.getRange("D"+n).getValue();
var lname = ss.getRange("E"+n).getValue();
var city = ss.getRange("I"+n).getValue();
var street = ss.getRange("H"+n).getValue();
var phone = ss.getRange("G"+n).getValue();
var date = ss.getRange("A"+n).getValue();
var work = ss.getRange("B"+n).getValue();
var photo = ss.getRange("C"+n).getValue();
var site = ss.getRange("L"+n).getValue();
var find = ss.getRange("J"+n).getValue();
var referrer = ss.getRange("K"+n).getValue();
var contact = ContactsApp.createContact(fname, lname, email);
var group = ContactsApp.getContactGroup('emf');
group.addContact(contact);
var contacts = ContactsApp.getContactsByName(fname + ' ' + lname);
var setaddress = contacts[0].addAddress(ContactsApp.Field.HOME_ADDRESS,street + " " + city);
var setphone = contacts[0].addPhone(ContactsApp.Field.MAIN_PHONE,phone);
for (var i in contacts) {
contacts[i].setNotes(date + "\n\n" + work + "\n\n" + photo + "\n\n" + site + "\n\n" + find + " " + referrer + "\n\n-- eom --\n\n");}
}
}
}
1 is the first row using A1Notation with getRange(). The first iteration is trying to getValue() of F0. Changing the n to start at 1 and n <= data.length should get the ranges you are looking for.
...
for(var n=1;n<=data.length;n++){
if(data[n-1] == 'done'){
var email = ss.getRange("F"+n).getValue(); // Range not found error
...
edit: One thing to note the var data = ss.getRange("N1:N").getValues(); range is going to loop over all 1000 default rows. This may not be ideal if your data set is significantly smaller than 1000 rows.

Filter 2 struct/ arrays by mapping by specific

Im a new user using swift 3 and xcode 8.3. Currently facing a problem to filter 2 array/struc where in console output as below:
A_List : Optional([117, 115, 18])
B_List : Optional([{
URL = "169.jpeg";
categories = "A";
description = "description XXX";
height = 128;
id = 1;
likes = "1.00";
name = "Cake - Baked";
price = "13.78";
width = 128;
}, {
URL = "1622.jpeg";
categories = "A";
description = "Baked till golden";
height = 128;
id = 15;
likes = "1.00";
name = "Croissant";
price = "3.71";
width = 128;
}, {
URL = "11.jpeg";
categories = "A";
description = "description Crispy.";
height = 128;
id = 18;
likes = "1.00";
name = "Plain";
price = "2.65";
width = 128;
}, {
URL = "1622.jpeg";
categories = "A";
description = "A ";
height = 128;
id = 103;
likes = "1.00";
name = "America Pie";
price = "2.12";
width = 128;
}, {
URL = "11.jpeg";
categories = "B";
description = "Puff";
height = 128;
id = 115;
likes = "1.00";
name = "Puff";
price = "2.12";
width = 128;
}, {
URL = "168.jpeg";
categories = "C";
description = "description YYY";
height = 128;
id = 117;
likes = "1.00";
name = "Normal";
price = "3.18";
width = 128;
}])
I want to return B_List full info as var filtered_List = [AnyObject]() where only contains of A_List id number 117, 115, and 18 which look like as below:
filtered_List : Optional([{
URL = "11.jpeg";
categories = "A";
description = "description Crispy.";
height = 128;
id = 18;
likes = "1.00";
name = "Plain";
price = "2.65";
width = 128;
}, {
URL = "11.jpeg";
categories = "B";
description = "Puff";
height = 128;
id = 115;
likes = "1.00";
name = "Mini Puff";
price = "2.12";
width = 128;
}, {
URL = "168.jpeg";
categories = "C";
description = "description YYY";
height = 128;
id = 117;
likes = "1.00";
name = "Normal";
price = "3.18";
width = 128;
}])
I have tried few code and read tutorial in youtube, but unfortunately did not find any solution and it limited to swift2 sample.
Currently, my code tried as below:
var filtered_List = [AnyObject]()
let fullrList = B_List?.map{$0["id"] as! String}.map{_ in A_List}
filtered_List.append(fullrList as AnyObject )
print("result :\(filtered_List)")
Very Appreciated if someone expert can guide or give your solution here.
You should store your desired IDs in a Set, rather than an Array. You're just need a simple filter operation:
let desiredIds: Set = [117, 115, 18]
B_List.filter{ $0["id"].map{ desiredIds.contains($0) } ?? false } as [AnyObject]
Thanks for everyone who reply this topic specially to #Alexander. Here my solutions to share that may not the perfect one as others.
var resultAnyObject = [AnyObject]()
var aListIds = [String]()
for i in A_List! {
aListIds.append(i as! String)
}
//#Alexander : thanks for code below:
let desiredIds = aListIds
let fullList = B_List?.filter{ $0["id"].map{desiredIds.contains($0 as! String) } ?? false };
resultAnyObject.append(fullList as AnyObject)
print("Result of filtered_List :\(resultAnyObject)")

TYPO3 Formhandler finisher does not write to database

After the TYPO3 (6.1.7) website of a customer has gone online, the Formhandler forms do not work correctly anymore. They do send an email, but it seems that they do not execute the Finisher_DB for writing into the database anymore.
The TypoScript settings look like this:
plugin.Tx_Formhandler.settings {
debug = 0
# GENERAL CONFIGURATION
name = Default
addErrorAnchors = 1
formValuesPrefix = formhandler
fillValueMarkersBeforeLangMarkers = 1
# ERRORS LAYOUT
singleErrorTemplate {
totalWrap = <div>|</div>
singleWrap = <span class="error">|</span><br />
}
errorListTemplate {
totalWrap = <ul>|</ul>
singleWrap = <li class="error">|</li>
}
validators {
1.class = Tx_Formhandler_Validator_Default
1.config {
fieldConf {
wish.errorCheck.1 = required
alternative.errorCheck.1 = required
firstname.errorCheck.1 = required
surname.errorCheck.1 = required
nationality.errorCheck.1 = required
dateofbirth.errorCheck.1 = required
phone.errorCheck.1 = required
email.errorCheck.1 = required
street.errorCheck.1 = required
zip.errorCheck.1 = required
city.errorCheck.1 = required
country.errorCheck.1 = required
}
}
}
# Finishers configuration
finishers {
1.class = Tx_Formhandler_Finisher_Mail
1.config {
checkBinaryCrLf = registrationMessagePlain, registrationMessageHtml
limitMailsToUser = 10
admin {
}
user {
}
}
2.class = Tx_Formhandler_Finisher_DB
2.config{
table = tx_chilifhregistration
key = uid
fields {
timeslot = Sommerplatz
timeslot_july.mapping = timeslotSummerJuly
timeslot_august.mapping = timeslotSummerAugust
timeslot_september.mapping = timeslotSummerSeptember
wish.mapping = wish
wishcategory11.mapping = wishCategory11
wishcategory19.mapping = wishCategory19
wishcategory22.mapping = wishCategory22
wishcategorydb.mapping = wishCategoryDb
alternative.mapping = alternative
alternativecategory11.mapping = alternativeCategory11
alternativecategory19.mapping = alternativeCategory19
alternativecategory22.mapping = alternativeCategory22
alternativecategorydb.mapping = alternativeCategoryDb
salutation.mapping = salutation
firstname.mapping = firstname
surname.mapping = surname
nationality.mapping = nationality
dateofbirth.mapping = dateofbirth
phone.mapping = phone
email.mapping = email
street.mapping = street
zip.mapping = zip
city.mapping = city
country.mapping = country
salutation2.mapping = salutation2
firstname2.mapping = firstname2
surname2.mapping = surname2
nationality2.mapping = nationality2
dateofbirth2.mapping = dateofbirth2
phone2.mapping = phone2
email2.mapping = email2
street2.mapping = street2
zip2.mapping = zip2
city2.mapping = city2
country2.mapping = country2
}
}
}
}
What could be the problem?
You should better use the predef-definition-style for forms. This will save you trouble with multiple forms and is a cleaner implementation.
plugin.Tx_Formhandler.settings.predef.yourformularname { ...config... }
You can find a bunch of examples on the offical site/examples
I assume that your admin and user mail-config is only empty because you won´t post any customerinformation?
Did the form work if you fill in every single field?
In my own usecases all field i map with the finisher are required, maybe you should set a ...IfEmpty-option for non-require fields.
Here are the available ifEmpty-options.

Share primary Contacts along with the Opportunity using Sales Force to Sales Force Connector

Lead - gets converted to an Account , Contact and an Opportunity
I developed a trigger which shares an Opportunity and related Account with another Org of ours, and the piece i am missing is sharing the Contact along with this . Need some help for sharing the contact also.
Trigger autoforwardOpportunity on Opportunity(after insert) {
String UserName = UserInfo.getName();
String orgName = UserInfo.getOrganizationName();
List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>(
[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']
);
System.debug('Size of connection map: '+connMap.size());
List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();
for(Integer i =0; i< Trigger.size; i++) {
Opportunity Opp = Trigger.new[i];
String acId = Opp.Id;
System.debug('Value of OpportunityId: '+acId);
for(PartnerNetworkConnection network : connMap) {
String cid = network.Id;
String status = network.ConnectionStatus;
String connName = network.ConnectionName;
String AssignedBusinessUnit = Opp.Assigned_Business_Unit__c;
System.debug('Connectin Details.......Cid:::'+cid+'Status:::'+Status+'ConnName:::'+connName+','+AssignedBusinessUnit);
if(AssignedBusinessUnit!=Null && (AssignedBusinessUnit.equalsIgnoreCase('IT') || AssignedBusinessUnit.equalsIgnoreCase('Proservia'))) {
// Send account to IT instance
PartnerNetworkRecordConnection newAccount = new PartnerNetworkRecordConnection();
newAccount.ConnectionId = cid;
newAccount.LocalRecordId = Opp.AccountId;
newAccount.SendClosedTasks = true;
newAccount.SendOpenTasks = true;
newAccount.SendEmails = true;
newAccount.RelatedRecords = 'Contact';
System.debug('Inserting New Record'+newAccount);
insert newAccount;
// Send opportunity to IT instance
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
newrecord.ConnectionId = cid;
newrecord.LocalRecordId = acId;
newrecord.SendClosedTasks = true;
newrecord.SendOpenTasks = true;
newrecord.SendEmails = true;
//newrecord.ParentRecordId = Opp.AccountId;
System.debug('Inserting New Record'+newrecord);
insert newrecord;
}
}
}
}
newrecord.RelatedRecords = 'Contact,Opportunity'; //etc

Resources