why DataType.EmailAddress converted link automatically? - asp.net-mvc-3

I'm using a model with DataType.EmailAddress. I would like to modify the address link in the run time, however it already has email link automatically that prevents my modification.
#{
var subject = "";
if (Model.Name.Length > 30)
{
subject = Model.Name.Substring(0, 30) + "...";
}
else
{
subject = Model.Name;
}
}
model => model.email
But I got
<a href="mailto:emailaddress">emailaddress</a>
instead of
emailaddress
Why the email address is converted into link form automatically? And how to stop it? I would like to keep the datatype to use validation though.

You're trying to print the value of the property: #model.Email.
DisplayFor is not what you want.
Also, you need to URL-encode the subject parameter, including the space after Re:.

Related

Dynamics 365 API link between ActivityPointer and activitytypecode global option set

I am reading data from the ActivityPointer entity in Dynamics 365 via the API and I want to link the activitytypecode field value to the activitypointer_activitytypecode global option set, which I believe is the correct one. However the values don't seem to match. In the ActivityPointer.activitytypecode field I have values such as:
phonecall
bulkoperation
email
appointment
task
But those values don't appear in the option set definition, using this query: GlobalOptionSetDefinitions(Name='activitypointer_activitytypecode')
The option set has the code values (e.g. 4202 for Email) and the different descriptions in all languages, but nothing matches back to the values on ActivityPointer
Optionset is just key value pairs (4202: Email and so on), If you want to get the formatted text value of optionset (Email, Fax, etc) from your web api query results - then you have to use activitytypecode#OData.Community.Display.V1.FormattedValue to get it. Read more
I recommend this article for complete understanding of CRM activities.
If you are looking for the code integer value in your resultset, that seems to be an issue and the result is not the expected one - old SO thread
The problem is that if you are reading activitytypecode in code, then you will know that you get a string value. This is the logical name of the activity entity, e.g. "email", "phonecall" etc.
If you look at the definition of activitytypecode in Power Apps then it shows it as "Entity name" (i.e. text) but using the classic solution editor it shows as the global activitypointer_activitytypecode option set, which contains values for "Email", "Phone Call" etc.
I am sure that there should be a simple way of converting from activitytypecode (i.e. entity name) to activitypointer_activitytypecode (i.e. option set), but I've yet to find it.
What I am doing is retrieving the global activitypointer_activitytypecode option set, so I have access to all of the text values. Then retrieve details about the entity indicated by activitytypecode, specifically what is of interesting is the display name. Then loop through the option set looking for a case-insensitive match on display name.
This is my C# code:
public int? GetActivityType(IOrganizationService service, string activityTypeCode)
{
// Get all activity types.
var optionSetRequest = new RetrieveOptionSetRequest()
{
Name = "activitypointer_activitytypecode"
};
var optionSetResponse = (RetrieveOptionSetResponse)service.Execute(optionSetRequest);
var optionSetMetadata = (OptionSetMetadata)optionSetResponse.OptionSetMetadata;
var optionValues = new Dictionary<string, int?>(StringComparer.OrdinalIgnoreCase);
foreach (var option in optionSetMetadata.Options)
{
foreach (var optionLabel in option.Label.LocalizedLabels)
{
optionValues[optionLabel.Label] = option.Value;
}
}
// Get the display name for the activity.
var retrieveEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Entity,
LogicalName = activityTypeCode
};
var retrieveEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveEntityRequest);
LocalizedLabelCollection entityLabels = retrieveEntityResponse.EntityMetadata.DisplayName.LocalizedLabels;
// Look up the display name in the option set values.
foreach (var entityLabel in entityLabels)
{
if (optionValues.TryGetValue(entityLabel.Label, out int? value))
{
return (Schema.GlobalOptionSet.ActivityType?)value;
}
}
// If we get here then we've failed.
return null;
}
That is making two API calls, so best avoided in any situations where performance might be an issue. I'm not saying the code is perfect, but it hasn't let me down yet. Even so, I would recommend making do with the logical names provided by activitytypecode if you can.

isolated storage in windows phone developement

Im using VS to develop a windows phone app. Im doing it wp8 but it doesnt matter because it the code works for 7 too. Anyway, I have a text box and a button. When the text from the text box is entered, and the button is clicked it adds that to isolated storage.
On my other page, I have a textblock. Which should display what I wrote in the text box. It does work, but first let me sho you my code.
if (appsettings.Contains("name"))
{
appsettings.Remove("name");
appsettings.Add("name", TitleTextBox.Text); //rename if already exists
}
and then the second page that collects the info is below.
if (appsettings.Contains("name"))
{
string content = appsettings["name"].ToString(); //converts to string
titleTextBlock.Text = content; //shows title in text block
}
The problem is, the "name" works. However, if I call it ANYTHING else it does not. I want to add a different name because i want to be able to input two lots. For example two text box's and then when you press the button and go to the other page, it has two textblocks displaying each string in each one. I can't seem to do this because only "name" works. Ive changed it to other names and it doesnt work. Does anyone know why?
IsolatedStorageSettings works as a Dictionary. If you want to acces a specific key it should exist in the Dictionary.
If you try to change the value that already exists you can do like this:
if (appSettings.Contains("key")) appSettings["key"] = "new value";
else appSettings.Add("key", "new value");
Don't also forget to save your appSettings:
appSettings.Save();
And also according to your code - in ISS you can put not only string - it can be any object, if you want to get it, you should make a cast or use as:
string content = (string)appsettings["name"]; //converts to string
string content = appsettings["name"] as string;
EDIT - after comments, rebuild once more
If you want to have a to-do-list and you know that every task has its specific title, description and time then I would advise to create a special class for this, for example:
public class myTodo
{
public string TaskTitle { get; set; }
public string TaskDescription { get; set; }
public TimeSpan ElapsedTime { get; set; }
}
I used TimeSpan because I think it's easier to manage Time with it. Then if you want to Save/Load your myTodo you can do like this:
// create an example of your task
myTodo newTask = new myTodo() { TaskTitle = "Clean", TaskDescription = "Clean room", ElapsedTime = new TimeSpan(2, 0, 0) };
// add it to ISS and save
if (appSettings.Contains("firatTask")) appSettings["firatTask"] = newTask;
else appSettings.Add("firatTask", newTask);
appSettings.Save();
// try to load
myTodo read = appSettings["firatTask"] as myTodo;
You can access your item like this:
read.Title = TitleTextBox.Text; // and so on
Consider also making a List<myToDo> and be aware that ISS shoul also handle this:
List<myTodo> listJob = new List<myTodo>();
listJob.Add(firstTask); // firstTask is myToDo
listJob.Add(secondTask); // secondTask is myToDo
if (appSettings.Contains("listTask")) appSettings["listTask"] = listJob;
else appSettings.Add("listTask", listJob);
appSettings.Save();
List<myTodo> readList = appSettings["listTask"] as List<myTodo>;

Codeigniter sending out multiple emails

I am using codeigniters email class inside an Expression Engine plugin (EE runs off CI).
For some reason each time the plugin is run it sends out 2 emails, instead of 1. The emails are identical.
{exp:cdwd_emailer:questionnaire type="{segment_3}" entry_id="{segment_4}"}
Here is the function being called by the above.
public function questionnaire() {
$type = $this->EE->TMPL->fetch_param('type');
$typeLower = str_replace("-", " ", $type);
$typeUpper = ucwords($typeLower);
print_r($type);
$entry_id = $this->EE->TMPL->fetch_param('entry_id');
$subject = $typeUpper.' Questionnaire Submission';
$fromEmail = 'email#email.com';
$fromName = 'Test Name';
$toEmail = 'email#email.com';
$message = '
<p>A new '.$typeLower.' has been submitted.</p>
<p>Please click here to view this submission</p>
';
$this->EE->load->library('email');
$this->EE->email->set_mailtype("html");
$this->EE->email->from($fromEmail, $fromName);
$this->EE->email->to($toEmail);
$this->EE->email->subject($subject);
$this->EE->email->message($message);
$this->EE->email->send();
}
Can anyone tell me why? I can't figure it out. I printed out the contents of the type and entry_id params to check only 1 of each are being collected.
Thanks
I think you have to clear you email object after sending mail.
As per Expression Engine, you have to call:
ee()->email->clear();
For your case:
$this->EE->email->clear();

cfscript email validation in coldfusion

I'm trying to get this bit of code in my cfscript tag to work. I've searched and searched but have some up with nothing which will work to validate the email address.
If the email address is blank it will return the errormessage but if I just type on character, it will let it pass.
I'm pretty new to scripting in CF so any help would be appreciated.
if (isDefined("form.email"))
{
if (form.email is "")
{
errormessageemail = "Please enter a valid Email Address!";
}
else if (not form.email is "")
{
email = form.email;
function validate_email(str,email) {
if( not len(trim(arguments.str)) or not refind("^[0-9A-Za-z.'+_-]+#([0-9A-Za-z-]+\.)+[A-Za-z]+$", trim(arguments.str)) ) {
errormessageemail = "Please enter a valid Email Address! Ex. abc#abc.com";
}
return errormessageemail;
}
}
}
It could be as simple as this:
if (StructKeyExists(form, "email") AND NOT isValid("email", form.email)) {
errormessageemail = "Please enter a valid Email Address!";
}
You don't validate if email is not posted. Blank string is not valid email, no need to check it specially.
Note: someone may argue that isValid/email does not work 100% properly. That's true, but rare problem. Use regex if you think so as well.
Here's the code I use for checking for email validity:
LOCAL.Email = trim(lCase(ARGUMENTS.Email));
LOCAL.IsValid = reFindNoCase("^[A-Z0-9._%+-]+#[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$", LOCAL.Email);
And you should test for your form with structKeyExists, not isDefined, like the other respondent suggested. The structKeyExists function searches a specific scope for the variable. isDefined searches any and every scope.
if (StructKeyExists(form, "email") AND NOT isValid("email", form.email)) {
errormessageemail = "Please enter a valid Email Address!";
}
Simply Email validity Check in CFM
<cfif isValid("email", #Form.email#) >
<cfoutput>Email Address is valid</cfoutput>
<cfelse>
<cfoutput>Email Address is invalid</cfoutput>
</cfelse>

Remove First Name, Last Name and confirm password fields in account create page

I searched a lot to remove required fields like first name, Last name and confirm passwordfields in account create page.
So far i renamed required value from 1 to 0 from the table eav_attribute
After this i hided first name, Last Name, Confirm Password from register.phtml
But still i'm getting
The first name cannot be empty, The Last name cannot be empty, etc,..
Did any one know how to do this ?
Please give me a idea to solve this..
You have to change two more files:
Change /js/prototype/validation.js and comment out the following lines:
['validate-cpassword', 'Please make sure your passwords match.', function(v) {
var conf = $('confirmation') ? $('confirmation') : $$('.validate-cpassword')[0];
var pass = false;
if ($('password')) {
pass = $('password');
}
var passwordElements = $$('.validate-password');
for (var i = 0; i < passwordElements.size(); i++) {
var passwordElement = passwordElements[i];
if (passwordElement.up('form').id == conf.up('form').id) {
pass = passwordElement;
}
}
if ($$('.validate-admin-password').size()) {
pass = $$('.validate-admin-password')[0];
}
return (pass.value == conf.value);
}],
After that, you also have to change the Magento Customer Core model. There are two types of validation: through the front-end javascript and in the backend Customer model.
Rewrite the model with your own customer module. Then copy the validate() public function. And comment out the following lines:
$confirmation = $this->getConfirmation();
if ($password != $confirmation) {
$errors[] = Mage::helper('customer')->__('Please make sure your passwords match.');
}

Resources