Set up the variable for URL link in ColdFusion - coldfusion-11

How to set up a variable on the root directory for the url link in ColdFusion?
I set up the variable on the root directory for the url link, appweb\instance.cfm:
<CFSCRIPT>
...
...
Application.MainLink = "http://www.ucdavis.edu/index.html";
</CFSCRIPT>
I have a file under appweb/costsharing/footer.cfm to use the variable for url link, but it doesn't work.
<br />
<br />
<div align="center">
<b>Need Help? Visit the <a href="#Application.MainLink#" target=_blank>Cost Sharing Help</a></b>
</div>
<br />
<br />
<CFInclude Template="../OnRequestEnd.cfm">
</body>
</html>
Any suggestion?

You can define.
<cfset Application.MainLink = "http://www.ucdavis.edu/index.html">
OR
<cfset Application.MainLink = "http://www.ucdavis.edu/index.cfm">
If you want to point any sub-directory you can define in your application.cfc root directory for example:
<cfset application.rootDir = getDirectoryFromPath(getCurrentTemplatePath()) />
In your code you can use:
#application.rootDir#/appweb/costsharing/index.cfm
USE this for link
<a href="<cfoutput>#Application.MainLink#</cfoutput>" target=_blank>Cost Sharing Help</a>

I had the same issue, for some reason beyond my understanding you need to put http:// in front. I am aware of the late response but I am doing this for future people that will have the same issue. So this can be used:
<a href="http://#Application.MainLink#" target=_blank>

Related

Generating html with CFSaveContent, images don't display

I'm trying to use cfsavecontent to send an html page (with CSS formatting). However, when I send the variable via cfmail, everything arrives fine, except the images.
<cfsavecontent variable="YourImg">
<table class="table_css">
<tr>
<td>
<p> your image is this:</p>
<img src="/imgs/image.jpg">
</td>
</tr>
</table>
</cfsavecontent>
<cfmail from="email#hotmail.com" to="email#gmail.com" subject="test email" type="html">
test:
<br /><br /><br />
#YourImg#
<br /><br /><br />
</cfmail>
This shows me the HTML table, formatted with the CSS, but the image looks like it is missing. Can anybody explain why?
<cfsavecontent> only saves the generated markup in between the tag into a string. You can <cfdump var="#YourImg#"> and see for yourself.
<cfdocument> can capture the image, but into a pdf file. Doc # https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-d-e/cfdocument.html
To attach files to the email, please look into <cfmailparam> # https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfmailparam.html
Example 2: This view-only example displays an image in the body of an
HTML message.
<cfmail type="HTML"
to = "#form.mailto#"
from = "#form.mailFrom#"
subject = "Sample inline image">
<cfmailparam file="C:\Inetpub\wwwroot\web.gif"
disposition="inline"
contentID="image1">
<p>There should be an image here</p>
<img src="cid:image1">
<p>After the picture</p>
</cfmail>

Thymeleaf How to check current URL?

i was familiar with JSTL before and thymeleaf is something new to me.
What i want is to check if the current URL is the index page (/index), if so then make visible a div.
Here is a JSTL equivalent example
<c:set var="url" value="${ pageContext.request.requestURI }" />
<c:if test="${url=='/example/WEB-INF/views/inbox.jsp'}">
...
</c:if>
Try this:
<div th:if="${#httpServletRequest.requestURI == '/example/WEB-INF/views/inbox.jsp'}">
some content
</div>

Undefined Index for $_POST (noob question!) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
I am just learning PHP and I keep getting an Undefined Index error. The book I'm learning from has an HTML form and a PHP page that processes the form, using the following format:
<!-- The form fields are all set up something like this -->
<input type="text" id="howlong" name="howlong" /><br />
// The PHP starts with one line like this for each of the form fields in the HTML
$how_long = $_POST ['howlong'];
// And there is one line for each one like this to output the form data:
echo ' and were gone for ' . $how_long . '<br />';
The example I'm working with has about 12 form fields.
What's odd is that not all of the variables throw this error, but I can't see a pattern to it.
I've checked that all HTML fieldnames match up with the PHP $_POST variable name I entered, and I've made certain that when I fill out the form and submit it that all fields are filled in with something. Interestingly, the completed code that can be downloaded for the book also throws this error.
I realize this code may not reflect best practices, it's from the first chapter of the book and obviously I am a noob :)
In case it makes a difference, I am using PHP 5.3.5 on XAMPP 1.7.4 with Windows 7 Home Premium.
Remember to set the method to POST on the form tag...
heres the code i used to try yours, and it worked to me:
in a file named test.php:
<html>
<body>
<form method="POST" action="testProc.php">
<input type="text" id="howlong" name="howlong" /><br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
and in testProc.php:
<?php
if (isset($_POST)) {
if (isset($_POST["howlong"])){
$howlong = $_POST['howlong'];
echo ' and were gone for ' . $howlong . '<br />';
}
}
?>
Just as an advise, to make display manipulation with stylesheets i recommend to put forms within a table, like this:
<html>
<body>
<form method="POST" action="testProc.php">
<table>
<tbody>
<tr>
<th>
<label for="howlong">How long? :</label>
</th>
<td>
<input type="text" id="howlong" name="howlong" />
</td>
</tr>
<tr>
<input type="submit" value="submit"/>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Hope you can use this...
you need to check that form is submitted and then you can try to use $_POST array, so you should put this code above:
if(isset($_POST['send'])) {
where "send" is name of submit button
You can test to see if a variable is set using the isset() function.
Also, not all HTML form elements will post a value in all cases. The common example is the checkbox; an unchecked checkbox doesn't form part of the the data posted back to the server. Therefore the $_POST element you're expecting to be set won't be.

How to pass data from viewbag to model in CSHTML

I'm having a hard time passing data to my model using viewbag.
Here is some example to enlighten you:
#model UCPBEscheatment.Models.aspnet_Membership
#{
ViewBag.Title = "AnswerForgotPassword";
}
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
#using (Html.BeginForm())
{
<em style="font-size:small">#Html.ValidationSummary(true, "Forgot Password was unsuccessful. Please correct the errors and try again.")</em>
<fieldset style="background-color:#f0f0f0">
<legend> Forgot Password </legend>
<br />
• Second step: <em style="color:Teal"> Answer your secret question</em>
<br /><br />
<b> Secret Question:</b> #ViewBag.question
<br /><br />
<b> Secret Answer: </b>#Html.EditorFor(a => a.PasswordAnswer)
<br /><br />
#{
INPUT CODE HERE TO PASS A VALUE TO THE MODEL USING VIEWBAG LIKE:
ex.
#MODEL.USERID = VIEWBAG.USERID
}
<input type="submit" value="Submit" />
</fieldset>
}
It doesn't work that way. You can't assign to the model that is being returned in the post. I'd suggest adding the user's id to the form url and using the id on the url to find the user that needs the password secret validated.
#using (Html.BeginForm("validatepassword","account",new { id = ViewBag.UserID }))
{
...
}
Or better yet, set the user id on the model and use it from there instead of the ViewBag, but still using it in the url to post back.

How do I unhide a CFDIV that has dynamic content with AJAX binding itself?

I have the following CFSELECT tags that are used to populate a text input:
<cfselect id="this" name="this" bind="cfc:Data.getThis()" bindonload="true" />
<cfselect id="that" name="that" bind="cfc:Data.getThat({p1})" />
<cfselect id="theOther" name="theOther" bind="cfc:Data.getTheOther({p1}, {p2})" />
The text input is the only value that needs to be submitted in a form:
<cfform name="addItem" method="post" action="somepage.cfm">
<cfinput
type="text"
id="item"
name="item"
bind="cfc:Data.getResult({this}, {that}, {theOther})" /><br />
<cfinput
type="submit"
name="addButton"
value="Add Item" />
</cfform>
I want the form and it's contents to be visible only when all three selections have been made, and there is a value for the text input. What is the best way to do this? I'm assuming some use of CFDIV is the best way, but I'm not sure how to load the dynamic content (the CFINPUTs) this way.
<cfselect id="this" name="this" bind="cfc:Data.getThis()" bindonload="true" onChange="toggleForm();" />
<cfselect id="that" name="that" bind="cfc:Data.getThat({p1})" onChange="toggleForm();" />
<cfselect id="theOther" name="theOther" bind="cfc:Data.getTheOther({p1}, {p2})" onChange="toggleForm();" />
<div id="theForm" style="display:none">
<cfform name="addItem" method="post" action="somepage.cfm">
<cfinput
type="text"
id="item"
name="item"
bind="cfc:Data.getResult({this}, {that}, {theOther})" /><br />
<cfinput
type="submit"
name="addButton"
value="Add Item" />
</cfform>
</div>
<script type="text/javascript">
function toggleForm(){
var a = document.getElementById("this").selectedIndex;
var b = document.getElementById("that").selectedIndex;
var c = document.getElementById("theOther").selectedIndex;
if (a > -1 && b > -1 && c > -1){
document.getElementById("theForm").style.display = "";
}
}
</script>
Personally I would simplify that JS a bit by using jQuery, but I don't know if you're already using jQuery on your site, and I don't want to be another "use jquery" empty answer; so this should work without jQuery, should you want/need to go without it. (But jQuery is awesome!)

Resources