How to integrate silverlight into aspx? Please explain - silverlight

I have created a Silverlight application now I want to embed it into my aspx page. Is there any video tutorial for this, which explains how to integrate silverlight in aspx page?

<head>
<title>AyarlarSLV</title>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
#silverlightControlHost {
height: 100%;
text-align:center;
}
</style>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
if (errorType == "ImageError" || errorType == "MediaError") {
return;
}
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n" ;
errMsg += "Code: "+ iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
Silverlight portion :
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/Silverlight.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="5.0.61118.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
</head>

Related

Edit button not redirecting on Salesforce mobile app

On Account page, I have a Button which opens a VF page which creates Task record. When I click Edit button on the Task record to update it and click Save, it's redirecting to the Task record page on Desktop in both classic and lightning mode. However, when I am performing same action on Mobile, upon clicking on Save, it is giving me error. Page doesn't exist. Enter a valid URL and try again.
public class Sim_NewTaskController {
//private Task taskObjectParent;
public Task taskObjectParent{get;set;}
private Task tempTask;
public String whoId{get;set;}
public String whatId{get;set;}
public String recordId{get;set;}
public String retURL{get;set;}
private String close;
// these three variables will set when log a call button will clicked on activity history
private String title;
private String tsk5;
private String followup;
public String inputValue{get;set;}
public List<MultiSelect> avaiableContactlList {get;set;}
public List<MultiSelect> avaiableGoalList {get;set;}
public List<MultiSelect> avaiableTopicList {get;set;}
public boolean isNAOProfile{get;set;}
public Integer totalAvaiableGoal {get;set;}
public Integer totalAvaiableTopic {get;set;}
public List<SelectOption> avaiableOptionsContacts{get;set;}
public String selectedContact{get;set;}
public string searchstring {get;set;}
//For SOS Profile
//Set<String> setSOSAvlTopics = new Set<String>{'Account Maintenance', 'Co-Management','Material Request','Referral Process','Divisions','Events','Issue Resolution','New Provider'};
public Sim_NewTaskController(ApexPages.StandardController stdController) {
totalAvaiableGoal = 0;
totalAvaiableTopic = 0;
//this.taskObjectParent = (Task)stdController.getRecord();
avaiableOptionsContacts = new List<SelectOption>();
selectedContact = searchText = '';
tempTask=new Task();
taskObjectParent=new Task();
whatId = ApexPages.currentPage().getParameters().get('what_id');
whoId = ApexPages.currentPage().getParameters().get('who_id');
recordId = ApexPages.currentPage().getParameters().get('id');
close = ApexPages.currentPage().getParameters().get('close');
retURL = ApexPages.currentPage().getParameters().get('retURL');
title = ApexPages.currentPage().getParameters().get('title');
tsk5 = ApexPages.currentPage().getParameters().get('tsk5');
followup = ApexPages.currentPage().getParameters().get('followup');
CheckProfile();
}
public void CheckProfile(){
isNAOProfile=false;
//If Logged in user prfile is NAO profile then replace picklist value like below
//Get looged in user profile
User objUser=[select profile.Name from user where id=:UserInfo.getUserId()];
if(objUser!=null && objUser.profile.Name=='NAO Profile'){
isNAOProfile=true;
}
}
public void filterFields() {
//Get Profile Name of logged in user
string profileName=[select profile.Name from user where id=:UserInfo.getUserId()].profile.Name;
System.debug('taskObjectParent.type------------'+taskObjectParent.type);
avaiableGoalList = new List<MultiSelect>();
avaiableTopicList = new List<MultiSelect>();
if(taskObjectParent.type == 'Sports Medicine Phone Call' || taskObjectParent.type == 'Sports Medicine Visit') {
avaiableTopicList.add(new MultiSelect(false, '2 Day Athlete Guarantee', null));
avaiableTopicList.add(new MultiSelect(false, 'Athletic Training Protocols', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Hospitals', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Medical Coverage', null));
avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
avaiableTopicList.add(new MultiSelect(false, 'New Physicians', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Sports Injury Clinics', null));
avaiableTopicList.add(new MultiSelect(false, 'Sponsorships', null));
avaiableTopicList.add(new MultiSelect(false, 'Team Physicals', null));
avaiableGoalList.add(new MultiSelect(false, 'Establishing New Relationships', null));
avaiableGoalList.add(new MultiSelect(false, 'Maintaining Relationship', null));
avaiableGoalList.add(new MultiSelect(false, 'Service Update', null));
}
if(taskObjectParent.type == 'E-mail or Fax' || taskObjectParent.type == 'Follow-Up' || taskObjectParent.type == 'Mailed Collateral/Document' || taskObjectParent.type == 'Office Staff Meeting' || taskObjectParent.type =='Outreach or CME Event' || taskObjectParent.type == 'Out of the Field' || taskObjectParent.type == 'Phone Call' || taskObjectParent.type == 'Unsuccessful Visit' ){
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Co-Management', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'New Provider', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho/Walk-In', null));
}
else {
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Co-Management', null));
avaiableTopicList.add(new MultiSelect(false, 'Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'New Provider', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho/Walk-In', null));
/* if(profileName=='SOS Profile'){
for(String st:setSOSAvlTopics){
avaiableTopicList.add(new MultiSelect(false, st, null));
}
}*/
for( Schema.PicklistEntry f : Task.Goal_of_Activity__c.getDescribe().getPicklistValues()) {
if(isNAOProfile==true){
if(f.getValue()!='CORE Referral Manager Training'){
avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
}
}
else{
avaiableGoalList.add(new MultiSelect(false, f.getLabel(), null));
}
}
}
//For Goal
system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Goal_of_Activity__c);
if(string.isNotBlank(taskObjectParent.Goal_of_Activity__c)){
for(MultiSelect goal : avaiableGoalList){
for(string str:taskObjectParent.Goal_of_Activity__c.split(';')){
if(goal.Name == str.trim()){
goal.isChecked = true;
}
}
}
totalAvaiableGoal = taskObjectParent.Goal_of_Activity__c.split(';').size();
}
system.debug('avaiableGoalList--111------------->' + avaiableGoalList);
/*if(isNAOProfile==true){
avaiableTopicList = new List<MultiSelect>();
avaiableTopicList.add(new MultiSelect(false, 'Account Maintenance', null));
avaiableTopicList.add(new MultiSelect(false, 'Divisions', null));
avaiableTopicList.add(new MultiSelect(false, 'Events', null));
avaiableTopicList.add(new MultiSelect(false, 'Issue Resolution', null));
avaiableTopicList.add(new MultiSelect(false, 'NAO Material Request', null));
avaiableTopicList.add(new MultiSelect(false, 'New Clinic', null));
avaiableTopicList.add(new MultiSelect(false, 'New Physician', null));
avaiableTopicList.add(new MultiSelect(false, 'NAO Referral Process', null));
avaiableTopicList.add(new MultiSelect(false, 'Quality Outcomes', null));
avaiableTopicList.add(new MultiSelect(false, 'Urgent Ortho', null));
}*/
//For Topics
system.debug(taskObjectParent.Id + ' =====> ' + taskObjectParent.Topics_Discussed__c);
if(string.isNotBlank(taskObjectParent.Topics_Discussed__c)){
for(MultiSelect goal : avaiableTopicList){
for(string str:taskObjectParent.Topics_Discussed__c.split(';')){
if(goal.Name == str.trim()){
goal.isChecked = true;
}
}
}
totalAvaiableTopic = taskObjectParent.Topics_Discussed__c.split(';').size();
}
system.debug('avaiableTopicList--2222------------->' + avaiableTopicList);
}
// Task cannot be created from contact. Button hidden
public PageReference loadNewTask(){
try{
taskObjectParent=new Task();
//Assign default value
taskObjectParent.ActivityDate=Date.Today();
if(recordId != null){
List<Task> taskList = [select whatId,whoId,ActivityDate ,Priority ,Status,
Activity_Cost__c,OwnerId,Visit_Duration__c,Description,Goal_of_Activity__c ,
Topics_Discussed__c,Subject, Type
from task where id=:recordId limit 1];
if(taskList!= null && taskList.size()>0)
{
taskObjectParent=taskList[0];
whatId = taskList[0].whatId;
whoId = taskList[0].whoId;
inputValue = taskList[0].Type;
}
}
if((whatId != null && !whatId.startsWith('001')) || (whoId!=null && !whoId.startsWith('003'))){
PageReference refObject = new PageReference('/00T/e');
refObject.getParameters().putAll(ApexPages.currentPage().getParameters());
refObject.getParameters().put('nooverride', '1');
refObject.setRedirect(true);
return refObject;
}else{
avaiableContactlList = new List<MultiSelect>();
filterFields();
//We do not create task through contact
if(whatId != null && whatId.startsWith('001')){
//get Account Id to fileter contact based on profile
Set<string> setAccountId=new Set<string>();
if(Test.isRunningTest()){
setAccountId.add(whatId);
}
string labelActId=Label.Core_Account_Id;
if(isNAOProfile==true){
labelActId=Label.NAO_Account_Id;
}
if(string.isNotBlank(labelActId)){
for(string st:labelActId.split(',')){
setAccountId.add(st);
}
for(Contact contactObject : [Select id,Name,Email, AccountId From Contact where
RecordType.Name='Internal Provider' AND Inactive__c = false order by Name]){
avaiableContactlList.add(new MultiSelect(false, contactobject.Name, contactObject.Id));
avaiableOptionsContacts.add(new SelectOption(contactObject.Id, contactObject.Name));
}
}
taskObjectParent.WhatId = whatId;
taskObjectParent.OwnerId = Userinfo.getUserId();
}
if(close != null && close =='1'){
taskObjectParent.Status = 'Completed';
}
// when task is created from log a call
System.debug('title > '+ title + 'followup > '+ followup + 'tsk5 > '+ tsk5);
if(title != null && title =='Referral Meeting' && followup !=null && followup == '1' && tsk5 != null && tsk5 == 'Referral Meeting'){
taskObjectParent.Status = 'Completed';
taskObjectParent.Type = title;
}
return null;
}
//return null;
}catch(Exception e){
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.FATAL,e.getMessage()));
return null;
}
}
public String searchText{get;set;}
public PageReference filterContacts(){
for(MultiSelect option : avaiableContactlList){
if(String.isBlank(searchText)){
option.isDisplay = '';
continue;
}
if(!option.Name.contains(searchText)){
option.isDisplay = 'none';
}
}
return null;
}
// for all activity objectives except 'Physician to physician visit' contact is not required.
public PageReference performSave(){
System.debug('############');
try{
string retId=ApexPages.currentPage().getParameters().get('retURL');
system.debug('retId------------>' + retId);
system.debug('recordId------------>' + recordId);
if(string.isBlank(retId)==null || retId==null){
retId=recordId;
}
system.debug('retId111------------>' + retId);
if(string.isBlank(retId)){
if(string.isNotblank(whatId)){
retId=whatId;
}
if(string.isNotblank(whoId)){
retId=whoId;
}
}
system.debug('retId222------------>' + retId);
//String retId = ApexPages.currentPage().getParameters().get('retURL');
boolean isContactSelected = false;
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
isContactSelected = true;
break;
}
}
List<Task> tasksToBeSaved = new List<Task>();
if(recordId == null){
if((taskObjectParent.Type == 'Physician-to-Physician Visit' || taskObjectParent.Type == 'Unsuccessful Physician-to-Physician Visit' || taskObjectParent.Type == 'Sports Medicine Phone Call' || taskObjectParent.Type =='Sports Medicine Visit') && isContactSelected == true){
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
Task taskObject = createTask(taskObjectParent,conObj.Value);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
}
}else{
Task taskObject = createTask(taskObjectParent,null);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
system.debug(' >>>>> === '+tasksToBeSaved);
upsert tasksToBeSaved;
system.debug(' >>>>> ------'+tasksToBeSaved);
system.debug('retId44------------>' + retId);
System.debug(' Current Url -- '+ApexPages.currentPage().getHeaders().get('Origin'));
System.debug(' > >> > >> > '+Apexpages.currentPage().getUrl());
//PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
//PageReference pg = new PageReference('/'+retId);
System.debug(' >> > > > 299 = = = '+retId);
PageReference pg = new PageReference(retId);
pg.setRedirect(true);
return pg;
// return null;
}else{
if(((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit' ) || (taskObjectParent.Type == 'Sports Medicine Visit' && inputValue != 'Sports Medicine Visit') || (taskObjectParent.Type == 'Sports Medicine Phone Call' && inputValue != 'Sports Medicine Phone Call') ) && isContactSelected == true){
for(MultiSelect conObj : avaiableContactlList){
if(conObj.isChecked){
Task taskObject = createTask(taskObjectParent,conObj.Value);
taskObject.Topics_Discussed__c = '';
taskObject.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObject.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObject.Goal_of_Activity__c += sltVal.Name + ';';
}
}
tasksToBeSaved.add(taskObject);
}
}
}else{
taskObjectParent.Subject = taskObjectParent.Type;
taskObjectParent.Topics_Discussed__c = '';
taskObjectParent.Goal_of_Activity__c = '';
for(MultiSelect sltVal : avaiableTopicList){
if(sltVal.isChecked){
taskObjectParent.Topics_Discussed__c += sltVal.Name + ';';
}
}
for(MultiSelect sltVal : avaiableGoalList){
if(sltVal.isChecked){
taskObjectParent.Goal_of_Activity__c += sltVal.Name + ';';
}
}
upsert taskObjectParent;
}
System.debug('=:tasksToBeSaved:=' +tasksToBeSaved);
if(!tasksToBeSaved.isEmpty()){
upsert tasksToBeSaved;
}
//PageReference pg = new PageReference('/'+ApexPages.currentPage().getParameters().get('retURL'));
//PageReference pg = new PageReference('/'+retId);
PageReference pg = new PageReference(retId);
System.debug(' >> > > > 342 = = = '+retId);
pg.setRedirect(true);
return pg;
// return null;
}
}catch(Exception e){
System.debug(e);
return null;
}
//return null;
}
private Task createTask(Task taskObjectParent1,String contactIdStr){
Task taskObject = new Task();
if((taskObjectParent.Type == 'Physician-to-Physician Visit' && inputValue != 'Physician-to-Physician Visit') || (taskObjectParent.Type == 'Sports Medicine Visit' && inputValue != 'Sports Medicine Visit') || (taskObjectParent.Type == 'Sports Medicine Phone Call' && inputValue != 'Sports Medicine Phone Call')){
}else{
taskObject.Id = taskObjectParent1.Id;
}
taskObject.Type = taskObjectParent1.Type;
//taskObject.Subject = taskObjectParent1.Type;
taskObject.whatId = taskObjectParent1.whatId;
taskObject.whoId = contactIdStr;
taskObject.OwnerId = taskObjectParent1.OwnerId;
taskObject.Description = taskObjectParent1.Description;
taskObject.ActivityDate = taskObjectParent1.ActivityDate;
taskObject.Status = taskObjectParent1.Status;
taskObject.Priority = taskObjectParent1.Priority;
taskObject.Goal_of_Activity__c = taskObjectParent1.Goal_of_Activity__c;
taskObject.Topics_Discussed__c = taskObjectParent1.Topics_Discussed__c;
taskObject.Visit_Duration__c = taskObjectParent1.Visit_Duration__c;
taskObject.Activity_Cost__c = taskObjectParent1.Activity_Cost__c;
return taskObject;
}
//Wrapper class
public class MultiSelect{
public boolean isChecked{get;set;}
public String Name{get;set;}
public Id Value{get;set;}
public String isDisplay{get;set;}
public MultiSelect(boolean isChecked, String Name, Id Value){
this.isChecked = isChecked;
this.Name = Name;
this.Value = Value;
this.isDisplay = '';
}
}
}```
Visualforce page -
<apex:page standardController="Task" id="thePageId" extensions="Sim_NewTaskController" tabStyle="Task" action="{!loadNewTask}">
<head>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
</head>
<apex:includeScript value="/soap/ajax/32.0/apex.js"/>
<apex:outPutPanel id="myMSG">
<apex:pageMessages id="msg" />
</apex:outPutPanel>
<script>
function setFocusOnLoad() {}
function toggleComponent(taskType,componentToToggle,taskId){
console.log('taskId : '+taskId);
//filterFields();
if(taskId == 'NULL' || taskId == ''){
var contactComponent = document.getElementsByClassName(componentToToggle)[0];
var selectedValue = taskType.value;
console.log(componentToToggle);
if(selectedValue == 'Physician-to-Physician Visit' || selectedValue == 'Unsuccessful Physician-to-Physician Visit' || selectedValue == 'Sports Medicine Visit' || selectedValue == 'Sports Medicine Phone Call'){
contactComponent.style.display ='block';
}else{
contactComponent.style.display ='none';
}
}else{
var contactComponent = document.getElementsByClassName(componentToToggle)[0];
var selectedValue = taskType.value;
console.log(componentToToggle);
var oldTaskType = String(document.getElementById('thePageId:newTaskPage:theHiddenInput').value);
if((oldTaskType != 'Physician-to-Physician Visit' && selectedValue == 'Physician-to-Physician Visit') || (oldTaskType != 'Sports Medicine Visit' && selectedValue == 'Sports Medicine Visit') || (oldTaskType != 'Sports Medicine Phone Call' && selectedValue == 'Sports Medicine Phone Call') ){
contactComponent.style.display ='block';
}else{
contactComponent.style.display ='none';
}
}
//alert(taskType.value);
filterFields(taskType.value);
}
function filterContactList(searchVal){
var y = document.getElementsByClassName("contactRow");
for (i = 0; i < y.length; i++) {
var title = y[i].title.toUpperCase();
if(title.search(searchVal.toUpperCase()) == 0){
y[i].style.display = '';
}else if(title.search(searchVal) == -1){
y[i].style.display = 'none';
}
}
}
</script>
<style>
<!-- .multilist{
float:left;
vertical-align:middle
}
.multilist p {
padding: 0;
text-align: center;
white-space: normal;
width: 50px;
margin:0;
}
.multilist .btn{
margin-top:3px;
margin-left:10px;
margin-right:10px;
}
.label{
width:100%;
font-weight:bold;
float:left;
}
.relatedToSection{
float:left;
padding-left:13.5%;
}-->
.searchTextBox::placeholder {
font-style:italic;
font-weight: bold;
text-shadow: 0.5px 0px 0.5px #000000;
opacity: 1;
}
.lookupInput {
position: relative;
}
.lookupInput a, .lookupInput a:hover, .lookupInput a:focus {
position: absolute;
width: 30px !important;
height: 30px !important;
right: 0;
top: -1px;
border: 0 !important;
background: transparent !important;
padding: 0 !important;
outline: none !important;
box-shadow: none !important;
}
.custom-tooltip .slds-popover {
display: none;
}
.custom-tooltip a:hover+.slds-popover {
display: block;
}
#media (min-width:767px){
select[multiple] {
min-height: 101px !important;
}
}
</style>
<!-- immediate="true" -->
<apex:slds />
<apex:form id="newTaskPage">
<apex:actionFunction action="{!filterFields}" name="filterFields" reRender="myMSG,taskInfo" >
<apex:param value="" name="tType" />
</apex:actionFunction>
<apex:sectionHeader title="Task" subtitle="New Task"/>
<apex:inputHidden value="{!inputValue}" id="theHiddenInput"/>
<div class="slds-card">
<div class="slds-card__header slds-grid slds-border_bottom slds-p-bottom_small" style="background-color: #fafaf9;">
<div class="slds-media slds-media_center slds-has-flexi-truncate">
<div class="slds-media__body">
<h2 class="slds-card__header-title slds-text-heading_small">
Task Edit
</h2>
</div>
<div class="slds-no-flex">
<apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand"/>
<apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>
</div>
</div>
</div>
<div class="slds-card__body slds-p-horizontal_small">
<div class="slds-m-bottom_small slds-p-around_xx-small" style="background-color: #fafaf9;"><strong>Related To</strong></div>
<div class="slds-form slds-form_horizontal">
<div>
<div style="max-width: 600px;">
<apex:outputPanel styleClass="relatedToSection">
<div class="slds-form-element">
<apex:outputLabel value="Account" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control slds-m-top_xxx-small">
<apex:outputField value="{!taskObjectParent.WhatId}" title="This will contain Related Account" label="Account" />
</div>
</div>
<!--apex:outputPanel ></apex:outputPanel-->
<!-- rendered="{!IF((taskObjectParent.Id = null),true,false)}" -->
<apex:outputPanel style="display:none" styleclass="taskContactMultiList" id="contactPenal" >
<apex:inputText styleClass="searchTextBox" value="{!searchText}" onkeyup="filterContactList(this.value);"
style="box-shadow: -10px -2px 25px -8px rgba(158,150,158,1);background-color:#f2f2ff;font-weight: bold;font-size:100%;padding: 5px; color: black; width: 314px;height: 20px;margin-left: 33%;margin-bottom: 1px;" html-placeholder="Select Contacts" >
</apex:inputText>
<div class="slds-form-element">
<apex:outputLabel value="Select Contact to create task" styleClass="slds-form-element__label" id="con12"/>
<div class="slds-form-element__control" style="padding-right: 82px;">
<div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
<table>
<apex:repeat value="{!avaiableContactlList}" var="con" id="myTable">
<tr class="contactRow" title="{!con.Name}">
<td width="20" class="slds-p-bottom_x-small">
<span class="slds-checkbox slds-checkbox_standalone">
<apex:inputCheckbox value="{!con.isChecked}" onclick="selectAllCheckboxes('contactCheckBoxId')" id="contactCheckBoxId"/>
<span class="slds-checkbox_faux"></span>
</span>
</td>
<td class="slds-p-bottom_x-small">
<label >
{!con.Name}
</label>
</td>
</tr>
</apex:repeat>
</table>
</div>
Total Number of Selected record :<span style="font-weight:bold" id="selContactSize">0</span>
</div>
</div>
</apex:outputPanel>
<div class="slds-form-element">
<apex:outputLabel value="Contact" styleClass="slds-form-element__label" rendered="{!IF((taskObjectParent.Id != null),IF(taskObjectParent.whoId == null,false,true),false)}"/>
<div class="slds-form-element__control">
<apex:outputField value="{!taskObjectParent.whoId}" title="this will contain related contact" label="Contact" rendered="{!IF((taskObjectParent.Id != null),IF(taskObjectParent.whoId == null,false,true),false)}"/>
</div>
</div>
</apex:outputPanel>
</div>
<div class="slds-m-bottom_small slds-p-around_xx-small" style="background-color: #fafaf9;"><strong>Task Information</strong></div>
<div id="taskInfo" style="max-width: 600px;">
<div class="slds-form-element">
<apex:outputLabel value="Activity Objective" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Type}" required="true" onchange="toggleComponent(this,'taskContactMultiList','{!taskObjectParent.Type}');onChangeActMethod()" styleClass="slds-select" Id="st" >
</apex:inputField>
<apex:actionFunction name="onChangeActMethod" action="{!filterFields}" rerender="refreshing"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Goal of Activity" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control" style="padding-right: 82px;">
<div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
<table>
<apex:repeat value="{!avaiableGoalList}" var="goal" >
<tr>
<td width="20" class="slds-p-bottom_x-small">
<span class="slds-checkbox slds-checkbox_standalone">
<apex:inputCheckbox onclick="selectAllCheckboxes('goalCheckBoxId')" value="{!goal.isChecked}" id="goalCheckBoxId"/>
<span class="slds-checkbox_faux"></span>
</span>
</td>
<td class="slds-p-bottom_x-small">
<label>
{!goal.Name}
</label>
</td>
</tr>
</apex:repeat>
</table>
</div>
Total Number of Selected record :<span style="font-weight:bold" id="setGoalsLength">{!totalAvaiableGoal}</span>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Due Date" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control" style="padding-right: 82px;">
<apex:inputField required="true" value="{!taskObjectParent.ActivityDate}" styleClass="slds-input"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Priority" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Priority}" styleClass="slds-select"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Status" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Status}" styleClass="slds-select"/>
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label">Activity Cost
<span class="custom-tooltip" style="position: relative;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a href="javascript:void(0)" aria-describedby="help">
<span class="slds-icon_container slds-icon-utility-info">
<svg class="slds-icon slds-icon slds-icon_xx-small slds-icon-text-default" aria-hidden="true">
<use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#info')}"></use>
</svg>
<span class="slds-assistive-text">Click here to learn more</span>
</span>
</a>
<div class="slds-popover slds-popover_tooltip slds-nubbin_bottom-left" role="tooltip" id="help" style="position:absolute;bottom:25px;left:-15px; width: 200px;">
<div class="slds-popover__body">
Enter the cost of any gift or other expense for the activity
</div>
</div>
</span>
</label>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Activity_Cost__c}" styleClass="slds-input"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Assigned To" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.OwnerId}" styleClass="slds-input"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Visit Duration" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Visit_Duration__c}" styleClass="slds-select" />
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Notes" styleClass="slds-form-element__label"/>
<div class="slds-form-element__control">
<apex:inputField value="{!taskObjectParent.Description}" styleClass="slds-textarea"/>
</div>
</div>
<div class="slds-form-element">
<apex:outputLabel value="Topics Discussed" styleClass="slds-form-element__label"/>
<apex:outputPanel id="refreshing">
<div class="slds-form-element__control" style="padding-right: 82px;">
<div class="slds-scrollable_y slds-m-top_x-small slds-m-bottom_small slds-p-around_x-small" style="max-height: 90px; border: 1px solid #dddbda; border-radius: .25rem;">
<table>
<apex:repeat value="{!avaiableTopicList}" var="topic">
<tr>
<td width="20" class="slds-p-bottom_x-small">
<span class="slds-checkbox slds-checkbox_standalone">
<apex:inputCheckbox value="{!topic.isChecked}" onclick="selectAllCheckboxes('topicCheckBoxId')" id="topicCheckBoxId"/>
<span class="slds-checkbox_faux"></span>
</span>
</td>
<td class="slds-p-bottom_x-small">
<label>
{!topic.Name}
</label>
</td>
</tr>
</apex:repeat>
</table>
</div>
Total Number of Selected record :<span style="font-weight:bold" id="selTopicSize">{!totalAvaiableTopic}</span>
</div>
</apex:outputPanel>
</div>
</div>
</div>
</div>
</div>
<div class="slds-card__footer slds-text-align_right">
<apex:commandButton action="{!performSave}" title="Save" value="Save" styleClass="slds-button slds-button_brand" />
<apex:commandButton action="{!cancel}" title="Cancel" value="Cancel" styleClass="slds-button slds-button_neutral"/>
<apex:commandButton action="{!edit}" title="Edit" value="{!URLFOR($Action.Task.Edit,recordId)}" styleClass="slds-button slds-button_neutral"/>
<!--<apex:outputLink value="{!URLFOR($Action.Task.Edit,recordId)}">Edit</apex:outputLink>-->
</div>
</div>
<script>
function selectAllCheckboxes(receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
var totalCount = 0;
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
if(inputCheckBox[i].checked == true){
totalCount = totalCount + 1;
}
}
}
//console.log('====>' + totalCount);
if(receivedInputID=='contactCheckBoxId'){
document.getElementById('selContactSize').innerHTML = totalCount;
}else if(receivedInputID=='goalCheckBoxId'){
document.getElementById('setGoalsLength').innerHTML = totalCount;
}else if(receivedInputID=='topicCheckBoxId'){
document.getElementById('selTopicSize').innerHTML = totalCount;
}
}
/*window.onload = ()=>{
alert('hello');
}*/
//console.log({!whatId});
function navigateTo() {
//debugger;
let data = '{!whatId}';
console.log(data+'--'+text);
if((typeof sforce != 'undefined') && sforce && (sforce.one)){
// Salesforce1 navigation
sforce.one.navigateToURL('https://www.google.com');
} /*else {
// Set the window's URL using a Visualforce expression
window.location.href = location.origin + '/' + {!whatId};
// site prefix helps when navigation in community
}*/
}
</script>
</apex:form>
</apex:page>

How can I print JSON in a proper format in angular JS?

I have the following code:
<div class="panel panel-default">
<div class="panel-heading"><strong>Parameters</strong>
</div>
{{ctrl.Params | json}}
<br>
<div>
<span class="glyphicon glyphicon-info-sign" ></span>
</div>
</div>
Now, what I want to do is print the entire JSON contained in ctrl.GlobalCFTParams in a pretty JSON format. What's happening right now is, it is getting displayed in a continuous fashion. Is there some filter or plugin I can use for this? Thanks!
https://codebeautify.org/jsonviewer - JSON beautified by this link is the kind of JSON I want to print on UI.
This fiddle might help you.
<div ng-app="app" ng-controller="ctrl">
<pre ng-bind-html="json | prettify"></pre>
</div>
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }
var app = angular.module("app", ['ngSanitize']);
app.filter('prettify', function () {
function syntaxHighlight(json) {
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
return syntaxHighlight;
});
app.controller('ctrl', function ($scope) {
var obj = {a:1, 'b':'foo', c:[false,'false',null, 'null', {d:{e:1.3e5,f:'1.3e5'}}]};
$scope.json = JSON.stringify(obj, undefined, 4);
});

Conditional ng-show

Is there any way to put a condition in the following:
<h3 ng-show="ctrl.loggedIn">
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
that is if the ctrl.loggedInUser.FirstName is undefined or null then it wouldn't print.
Click here to visit the project on github.
yes you can. use ng-if to add conditions in DOM
<h3 ng-show="ctrl.loggedIn" ng-if="ctrl.loggedInUser.FirstName">
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
h3 will only show if ctrl.loggedInUser.FirstName have some value
<h3 ng-show="ctrl.loggedIn && ( ctrl.loggedInUser.FirstName!=null || (ctrl.loggedInUser.FirstName!='undefined')")>
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
you can also do like
<h3 ng-hide="!ctrl.loggedIn && (ctrl.loggedInUser.FirstName==null || (ctrl.loggedInUser.FirstName=='undefined')")>
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
You can use ng-show
<h3 ng-show="ctrl.loggedInUser.FirstName!=undefined || ctrl.loggedInUser.FirstName!=null">
{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}
</h3>
<div ng-switch on="ctrl.loggedInUser.FirstName == null || ctrl.loggedInUser.FirstName == undefined || ctrl.loggedInUser.FirstName == ''">
<h3 ng-switch-when="true">Please log in.</h3>
<h3 ng-switch-when="false">{{ctrl.loggedInUser.FirstName + " " + ctrl.loggedInUser.LastName + " is logged in."}}</h3>
</div>
this worked for me.
thanks all for the ideas.

Form data not inserting in Wordpress database even though hard coded data gets inserted

I'm trying to build a form in Wordpress and inserting data from the form into the database. When I use hard coded data it works fine but if I change that to use variables from the form it is not inserting data at all. Any help would be much appreciated.
<?php
/*
Template Name: My Form Page
*/
?>
<?php
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
$selectedFood = 'None';
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
}
//establish connection
if(empty($errorMessage))
{
$db = mysql_connect("localhost","xxx","xxx");
if(!$db) die("Error connecting to MySQL database.");
mysql_select_db("xxx" ,$db);
$sql = "INSERT INTO wp_picnic_guest (name, yourname, moviename) VALUES ($name, $email, $message)";
mysql_query($sql);
}
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
//response generation function
$response = "";
//function to generate response
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//php mailer variables
$to = get_option('admin_email');
$subject = "Picnic Food from ".get_bloginfo('name');
$body = "From: $name\n E-Mail: $email\n Message: $message\n Selected Food:\n $selectedFood";
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, $body, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
<?php
function clearform()
{
document.getElementById("name").reset(); //don't forget to set the textbox ID
document.getElementById("email").reset(); //don't forget to set the textbox ID
document.getElementById("message").reset(); //don't forget to set the textbox ID
}
?>
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
<style type="text/css">
.error{
padding: 5px 9px;
border: 1px solid red;
color: red;
border-radius: 3px;
}
.success{
padding: 5px 9px;
border: 1px solid green;
color: green;
border-radius: 3px;
}
form span{
color: red;
}
</style>
<div id="respond">
<?php echo $response; ?>
<form action="<?php the_permalink(); ?>" method="post">
<p><label for="name">Name: <span>*</span> <br><input id= "name" type="text" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>"></label></p>
<p><label for="message_email">Email: <span>*</span> <br><input id="email" type="text" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>"></label></p>
<p>
<input type="checkbox" name="selectedFood[]" value="Tea"><label for="type4">Tea</label><?php
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
echo " Chosen"; }
else { echo ""; }
?> </br>
<input type="checkbox" name="selectedFood[]" value="Bread"><label for="type1">Bread</label></br>
<input type="checkbox" name="selectedFood[]" value="Cheese"><label for="type2">Cheese</label></br>
<input type="checkbox" name="selectedFood[]" value="Cake"><label for="type3">Cake</label> </br>
<p><label for="message_text">Message: <span>*</span> <br><textarea id="message" type="text" name="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></label></p>
<p><label for="message_human">Human Verification: <span>*</span> <br><input type="text" style="width: 60px;" name="message_human"> + 3 = 5</label></p>
<input type="hidden" name="submitted" value="1">
<p><input type="submit" />
</p>
</form>
</div>
</div><!-- .entry-content -->
</article><!-- #post -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Try wordpress default insert function for inserting values.
<?php
/*
Template Name: My Form Page
*/
?>
<?php
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
$selectedFood = 'None';
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
}
//establish connection
if(empty($errorMessage))
{
global $wpdb;
$wpdb->insert('wp_picnic_guest',
array('name'=>$name,
'yourname'=>$email,
'moviename'=>$message
) );
}
function PrepSQL($value)
{
// Stripslashes
if(get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote
$value = "'" . mysql_real_escape_string($value) . "'";
return($value);
}
//response generation function
$response = "";
//function to generate response
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//php mailer variables
$to = get_option('admin_email');
$subject = "Picnic Food from ".get_bloginfo('name');
$body = "From: $name\n E-Mail: $email\n Message: $message\n Selected Food:\n $selectedFood";
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) my_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
my_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
my_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = wp_mail($to, $subject, $body, strip_tags($message), $headers);
if($sent) my_contact_form_generate_response("success", $message_sent); //message sent!
else my_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) my_contact_form_generate_response("error", $missing_content);
?>
<?php
function clearform()
{
document.getElementById("name").reset(); //don't forget to set the textbox ID
document.getElementById("email").reset(); //don't forget to set the textbox ID
document.getElementById("message").reset(); //don't forget to set the textbox ID
}
?>
<?php get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_content(); ?>
<style type="text/css">
.error{
padding: 5px 9px;
border: 1px solid red;
color: red;
border-radius: 3px;
}
.success{
padding: 5px 9px;
border: 1px solid green;
color: green;
border-radius: 3px;
}
form span{
color: red;
}
</style>
<div id="respond">
<?php echo $response; ?>
<form action="<?php the_permalink(); ?>" method="post">
<p><label for="name">Name: <span>*</span> <br><input id= "name" type="text" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>"></label></p>
<p><label for="message_email">Email: <span>*</span> <br><input id="email" type="text" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>"></label></p>
<p>
<input type="checkbox" name="selectedFood[]" value="Tea"><label for="type4">Tea</label><?php
if(isset($_POST['selectedFood']) && is_array($_POST['selectedFood']) && count($_POST['selectedFood']) > 0){
$selectedFood = implode(', ', $_POST['selectedFood']);
echo " Chosen"; }
else { echo ""; }
?> </br>
<input type="checkbox" name="selectedFood[]" value="Bread"><label for="type1">Bread</label></br>
<input type="checkbox" name="selectedFood[]" value="Cheese"><label for="type2">Cheese</label></br>
<input type="checkbox" name="selectedFood[]" value="Cake"><label for="type3">Cake</label> </br>
<p><label for="message_text">Message: <span>*</span> <br><textarea id="message" type="text" name="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></label></p>
<p><label for="message_human">Human Verification: <span>*</span> <br><input type="text" style="width: 60px;" name="message_human"> + 3 = 5</label></p>
<input type="hidden" name="submitted" value="1">
<p><input type="submit" />
</p>
</form>
</div>
</div><!-- .entry-content -->
</article><!-- #post -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Firstly there is no needs for connecting database.It's already connected.
So remove code lines for connecting database.
Try with
$sql = "INSERT INTO wp_picnic_guest (name, yourname, moviename) VALUES ('$name', '$email', '$message')";

how to deal with an error message in wdcalendar?

I installed wdCalendar calendar (you can download it through this link: http://www.webappers.com/2010/06/08/wdcalendar-jquery-based-google-calendar-clone/
and you can see its demo through this link: http://www.web-delicious.com/jquery-plugins-demo/wdCalendar/sample.php), the problem is when I click on the button "New Event" (which exists at the left side in the top) a pop-pup window appears in which I see the following message error:
( ! ) Notice: Undefined index: id in C:\wamp\www\wdCalendar\edit.php on line 16
This is the script of the file "edit.php" :
<?php
include_once("php/dbconfig.php");
include_once("php/functions.php");
function getCalendarByRange($id){
try{
$db = new DBConnection();
$db->getConnection();
$sql = "select * from `jqcalendar` where `id` = " . $id;
$handle = mysql_query($sql);
//echo $sql;
$row = mysql_fetch_object($handle);
}catch(Exception $e){
}
return $row;
}
if($_GET["id"]){
$event = getCalendarByRange($_GET["id"]);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Calendar Details</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/dp.css" rel="stylesheet" />
<link href="css/dropdown.css" rel="stylesheet" />
<link href="css/colorselect.css" rel="stylesheet" />
<script src="src/jquery.js" type="text/javascript"></script>
<script src="src/Plugins/Common.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.form.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.validate.js" type="text/javascript"></script>
<script src="src/Plugins/datepicker_lang_US.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.datepicker.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.dropdown.js" type="text/javascript"></script>
<script src="src/Plugins/jquery.colorselect.js" type="text/javascript"></script>
<script type="text/javascript">
if (!DateAdd || typeof (DateDiff) != "function") {
var DateAdd = function(interval, number, idate) {
number = parseInt(number);
var date;
if (typeof (idate) == "string") {
date = idate.split(/\D/);
eval("var date = new Date(" + date.join(",") + ")");
}
if (typeof (idate) == "object") {
date = new Date(idate.toString());
}
switch (interval) {
case "y": date.setFullYear(date.getFullYear() + number); break;
case "m": date.setMonth(date.getMonth() + number); break;
case "d": date.setDate(date.getDate() + number); break;
case "w": date.setDate(date.getDate() + 7 * number); break;
case "h": date.setHours(date.getHours() + number); break;
case "n": date.setMinutes(date.getMinutes() + number); break;
case "s": date.setSeconds(date.getSeconds() + number); break;
case "l": date.setMilliseconds(date.getMilliseconds() + number); break;
}
return date;
}
}
function getHM(date)
{
var hour =date.getHours();
var minute= date.getMinutes();
var ret= (hour>9?hour:"0"+hour)+":"+(minute>9?minute:"0"+minute) ;
return ret;
}
$(document).ready(function() {
//debugger;
var DATA_FEED_URL = "php/datafeed.php";
var arrT = [];
var tt = "{0}:{1}";
for (var i = 0; i < 24; i++) {
arrT.push({ text: StrFormat(tt, [i >= 10 ? i : "0" + i, "00"]) }, { text: StrFormat(tt, [i >= 10 ? i : "0" + i, "30"]) });
}
$("#timezone").val(new Date().getTimezoneOffset()/60 * -1);
$("#stparttime").dropdown({
dropheight: 200,
dropwidth:60,
selectedchange: function() { },
items: arrT
});
$("#etparttime").dropdown({
dropheight: 200,
dropwidth:60,
selectedchange: function() { },
items: arrT
});
var check = $("#IsAllDayEvent").click(function(e) {
if (this.checked) {
$("#stparttime").val("00:00").hide();
$("#etparttime").val("00:00").hide();
}
else {
var d = new Date();
var p = 60 - d.getMinutes();
if (p > 30) p = p - 30;
d = DateAdd("n", p, d);
$("#stparttime").val(getHM(d)).show();
$("#etparttime").val(getHM(DateAdd("h", 1, d))).show();
}
});
if (check[0].checked) {
$("#stparttime").val("00:00").hide();
$("#etparttime").val("00:00").hide();
}
$("#Savebtn").click(function() { $("#fmEdit").submit(); });
$("#Closebtn").click(function() { CloseModelWindow(); });
$("#Deletebtn").click(function() {
if (confirm("Are you sure to remove this event")) {
var param = [{ "name": "calendarId", value: 8}];
$.post(DATA_FEED_URL + "?method=remove",
param,
function(data){
if (data.IsSuccess) {
alert(data.Msg);
CloseModelWindow(null,true);
}
else {
alert("Error occurs.\r\n" + data.Msg);
}
}
,"json");
}
});
$("#stpartdate,#etpartdate").datepicker({ picker: "<button class='calpick'></button>"});
var cv =$("#colorvalue").val() ;
if(cv=="")
{
cv="-1";
}
$("#calendarcolor").colorselect({ title: "Color", index: cv, hiddenid: "colorvalue" });
//to define parameters of ajaxform
var options = {
beforeSubmit: function() {
return true;
},
dataType: "json",
success: function(data) {
alert(data.Msg);
if (data.IsSuccess) {
CloseModelWindow(null,true);
}
}
};
$.validator.addMethod("date", function(value, element) {
var arrs = value.split(i18n.datepicker.dateformat.separator);
var year = arrs[i18n.datepicker.dateformat.year_index];
var month = arrs[i18n.datepicker.dateformat.month_index];
var day = arrs[i18n.datepicker.dateformat.day_index];
var standvalue = [year,month,day].join("-");
return this.optional(element) || /^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3-9]|1[0-2])[\/\-\.](?:29|30))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1,3,5,7,8]|1[02])[\/\-\.]31)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:16|[2468][048]|[3579][26])00[\/\-\.]0?2[\/\-\.]29)(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?: \d{1,3})?)?$|^(?:(?:1[6-9]|[2-9]\d)?\d{2}[\/\-\.](?:0?[1-9]|1[0-2])[\/\-\.](?:0?[1-9]|1\d|2[0-8]))(?: (?:0?\d|1\d|2[0-3])\:(?:0?\d|[1-5]\d)\:(?:0?\d|[1-5]\d)(?:\d{1,3})?)?$/.test(standvalue);
}, "Invalid date format");
$.validator.addMethod("time", function(value, element) {
return this.optional(element) || /^([0-1]?[0-9]|2[0-3]):([0-5][0-9])$/.test(value);
}, "Invalid time format");
$.validator.addMethod("safe", function(value, element) {
return this.optional(element) || /^[^$\<\>]+$/.test(value);
}, "$<> not allowed");
$("#fmEdit").validate({
submitHandler: function(form) { $("#fmEdit").ajaxSubmit(options); },
errorElement: "div",
errorClass: "cusErrorPanel",
errorPlacement: function(error, element) {
showerror(error, element);
}
});
function showerror(error, target) {
var pos = target.position();
var height = target.height();
var newpos = { left: pos.left, top: pos.top + height + 2 }
var form = $("#fmEdit");
error.appendTo(form).css(newpos);
}
});
</script>
<style type="text/css">
.calpick {
width:16px;
height:16px;
border:none;
cursor:pointer;
background:url("sample-css/cal.gif") no-repeat center 2px;
margin-left:-22px;
}
</style>
</head>
<body>
<div>
<div class="toolBotton">
<a id="Savebtn" class="imgbtn" href="javascript:void(0);">
<span class="Save" title="Save the calendar">Save(<u>S</u>)
</span>
</a>
<?php if(isset($event)){ ?>
<a id="Deletebtn" class="imgbtn" href="javascript:void(0);">
<span class="Delete" title="Cancel the calendar">Delete(<u>D</u>)
</span>
</a>
<?php } ?>
<a id="Closebtn" class="imgbtn" href="javascript:void(0);">
<span class="Close" title="Close the window" >Close
</span></a>
</a>
</div>
<div style="clear: both">
</div>
<div class="infocontainer">
<form action="php/datafeed.php?method=adddetails<?php echo isset($event)?"&id=".$event->Id:""; ?>" class="fform" id="fmEdit" method="post">
<label>
<span> *Subject:
</span>
<div id="calendarcolor">
</div>
<input MaxLength="200" class="required safe" id="Subject" name="Subject" style="width:85%;" type="text" value="<?php echo isset($event)?$event->Subject:"" ?>" />
<input id="colorvalue" name="colorvalue" type="hidden" value="<?php echo isset($event)?$event->Color:"" ?>" />
</label>
<label>
<span>*Time:
</span>
<div>
<?php if(isset($event)){
$sarr = explode(" ", php2JsTime(mySql2PhpTime($event->StartTime)));
$earr = explode(" ", php2JsTime(mySql2PhpTime($event->EndTime)));
}?>
<input MaxLength="10" class="required date" id="stpartdate" name="stpartdate" style="padding-left:2px;width:90px;" type="text" value="<?php echo isset($event)?$sarr[0]:""; ?>" />
<input MaxLength="5" class="required time" id="stparttime" name="stparttime" style="width:40px;" type="text" value="<?php echo isset($event)?$sarr[1]:""; ?>" />To
<input MaxLength="10" class="required date" id="etpartdate" name="etpartdate" style="padding-left:2px;width:90px;" type="text" value="<?php echo isset($event)?$earr[0]:""; ?>" />
<input MaxLength="50" class="required time" id="etparttime" name="etparttime" style="width:40px;" type="text" value="<?php echo isset($event)?$earr[1]:""; ?>" />
<label class="checkp">
<input id="IsAllDayEvent" name="IsAllDayEvent" type="checkbox" value="1" <?php if(isset($event)&&$event->IsAllDayEvent!=0) {echo "checked";} ?>/> All Day Event
</label>
</div>
</label>
<label>
<span> Location:
</span>
<input MaxLength="200" id="Location" name="Location" style="width:95%;" type="text" value="<?php echo isset($event)?$event->Location:""; ?>" />
</label>
<label>
<span> Remark:
</span>
<textarea cols="20" id="Description" name="Description" rows="2" style="width:95%; height:70px">
<?php echo isset($event)?$event->Description:""; ?>
</textarea>
</label>
<input id="timezone" name="timezone" type="hidden" value="" />
</form>
</div>
</div>
</body>
</html>
And the script below is the lines 16, 17 and 18 of the script above:
if($_GET["id"]){
$event = getCalendarByRange($_GET["id"]);
}
So my question is how to handle that error??...is there anyone who can help me??
Thanks in advance.
Sorry for the late reply here but I think the error is the $_GET['id'] is not set because you click the new event in the left side.
Try to use isset.
if(isset($_GET['id']) { }
The edit.php page is used to create new event and to edit an event.
Hope it helps. TH

Resources