Trying to send <cfmail> from a contact us static page. It will have a single recipient and I don't want to save it on the back end.
<cfcase value="contact">
<cfset caller.mainTitle = "Contact Us">
<div id="contact_form">
<cfform method="post" action="contact2" id="usrform">
First Name<br>
<input class="textbox" type="text" name="firstName" value="First Name" onfocus="if (this.value=='First Name') this.value='';">
<br>
Last Name<br>
<input class="textbox" type="text" name="lastName" value="Last Name" onfocus="if(this.value=='Last Name') this.value ='';">
<br>
Email<br>
<input class="textbox" type="text" name="email" value="Email" onfocus="if(this.value=='Email') this.value='';">
<br>
Phone Number<br>
<input class="textbox" type="text" name="phone" value="Phone Number" onfocus="if(this.value =='Phone Number') this.value='';">
<br>
<input type="submit" class='submitBtn'>
</cfform>
<br>
</div>
<div class="commentsTop">
<p style="color:black; font-size:18px; text-align:left;">We would love to hear from you!<p><br>
<textarea class="comments" rows="10" cols="100" name="comment" form="usrform" onfocus="if(this.value=='Enter your message here...') this.value='';">Enter your message here...</textarea>
</div>
</cfcase>
<cfcase value="contact2">
<cfmail to="test#test.com" from="tester#test.com" Subject="Message From Contact Us" type="HTML">
</cfmail>
</cfcase>
I have a form that I want to have attached as the body of the email. Wasn't sure if I need to have the form as a <cfform> or if that doesn't matter.
Here is what I will do:
I will use Normal html form (cfform is also fine)
Give action to form (it can be same page or you can have separate submit page.)
On submit page I will write logic to send mail.(if its simple mail sending and nothing complex is happening then cfm page is fine otherwise CFC is preferred)
Contactus.cfm
<form method="post" action="submitform.cfm" id="usrform">
First Name<br>
<input class="textbox" type="text" name="firstName" value="First Name" onfocus="if (this.value=='First Name') this.value='';">
<br>
Last Name<br>
<input class="textbox" type="text" name="lastName" value="Last Name" onfocus="if(this.value=='Last Name') this.value ='';">
<br>
Email<br>
<input class="textbox" type="text" name="email" value="Email" onfocus="if(this.value=='Email') this.value='';">
<br>
Phone Number<br>
<input class="textbox" type="text" name="phone" value="Phone Number" onfocus="if(this.value =='Phone Number') this.value='';">
<br>
<input type="submit" class='submitBtn'>
</form>
Submitform.cfm
Make sure you are passing correct credential and server details in cfmail
<cfmail to="test#test.com" from="tester#test.com" Subject="Message From Contact Us" type="HTML">
<!--- Your message body (you can use your form variable here) --->
FistName: #form.firstName#
LastName: #form.lastName#
</cfmail>
One file solution
<form method="post" action="?">
First Name<br>
<input class="textbox" type="text" name="firstName" value="First Name" onfocus="if (this.value=='First Name') this.value='';">
<br>
Last Name<br>
<input class="textbox" type="text" name="lastName" value="Last Name" onfocus="if(this.value=='Last Name') this.value ='';">
<br>
Email<br>
<input class="textbox" type="text" name="email" value="Email" onfocus="if(this.value=='Email') this.value='';">
<br>
Phone Number<br>
<input class="textbox" type="text" name="phone" value="Phone Number" onfocus="if(this.value =='Phone Number') this.value='';">
<br>
<p style="color:black; font-size:18px; text-align:left;">We would love to hear from you!<p><br>
<textarea class="comments" rows="10" cols="100" name="comment" onfocus="if(this.value=='Enter your message here...') this.value='';">Enter your message here...</textarea>
<input type="submit" class='submitBtn'>
</form>
<cfif cgi.request_method EQ "post">
<cfmail to="test#test.com" from="tester#test.com" Subject="Message From Contact Us" type="HTML">
<!--- Your message body (you can use your form variable here) --->
<cfloop index="i" list="#Form.FieldNames#" delimiters=",">
#i# = #Form[i]#<br>
</cfloop>
</cfmail>
</cfif>
Note: the Comments field was not inside of the form
Also see:
Display CFLoop Items in Order from Form
Related
Im trying to use the code I have found and its not working properly it is always saying that I am a robot do you have any idea why this will not work?
The Application.cfc has the site and secret key in it.
<script src="https://www.google.com/recaptcha/api.js?render=<cfoutput>#application.SiteKey#</cfoutput>"></script>
<cfif ISDEFINED('FORM.FirstName')> <!--- check if form was submitted and if so run code below --->
<cfhttp url="https://www.google.com/recaptcha/api/siteverify?secret=#application.SecretKey#&response=#FORM['g-recaptcha-response']#" result="Response" />
<cfset Return = deserializeJSON(Response.FileContent) />
<cfif Return.success IS 'true' AND Return.score GT 0.0> <!--- check if true and if score is greater than 0.5. Run code below if all good. --->
<cfoutput>Human: #FORM.FirstName# #FORM.LastName#</cfoutput>
<!--- you can do database entry and/or email results here --->
<cfelse> <!--- if not a human, do this. I usually remove the else part completely, but if you need to do something with the robot, do it here. --->
Most likely a robot.
</cfif>
<cfelse> <!--- show form --->
<form method="post" action="/contact.cfm"> <!--- submit form back to itself --->
First Name: <input name="FirstName" type="text"><br>
Last Name: <input name="LastName" type="text"><br>
<input name="submit" type="submit">
<input name="g-recaptcha-response" id="g-recaptcha-response" type="hidden" /> <!--- javascript below gives this a value from google. --->
</form>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('<cfoutput>#application.SiteKey#</cfoutput>', {action: 'homepage'})
.then(function(token) {
document.getElementById('g-recaptcha-response').value=token;
});
});
</script>
</cfif>
This is how I was able to get the form working properly.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://www.google.com/recaptcha/api.js?render=YOUR SITE KEY"></script>
<!-- contact form demo container -->
<cfif ISDEFINED('FORM.name')> <!--- check if form was submitted and if so run code below --->
<cfhttp url="https://www.google.com/recaptcha/api/siteverify?secret=#application.SecretKey#&response=#FORM['token']#" result="Response" />
<cfset Return = deserializeJSON(Response.FileContent) />
<cfif Return.success IS 'true' AND Return.score GT 0.5> <!--- check if true and if score is greater than 0.5. Run code below if all good. --->
<cfelse> <!--- if not a human, do this. I usually remove the else part completely, but if you need to do something with the robot, do it here. --->
</cfif>
<cfelse>
<section style="margin: 50px 20px;">
<div style="max-width: 768px; margin: auto;">
<!-- contact form -->
<div class="card">
<h2 class="card-header">Contact Form</h2>
<div class="card-body">
<form class="contact_form" method="post" action="contact.cfm">
<!-- form fields -->
<div class="row">
<div class="col-md-6 form-group">
<input name="name" type="text" class="form-control" placeholder="Name" required>
</div>
<div class="col-md-6 form-group">
<input name="email" type="email" class="form-control" placeholder="Email" required>
</div>
<div class="col-md-6 form-group">
<input name="phone" type="text" class="form-control" placeholder="Phone" required>
</div>
<div class="col-md-6 form-group">
<input name="subject" type="text" class="form-control" placeholder="Subject" required>
</div>
<div class="col-12 form-group">
<textarea name="message" class="form-control" rows="5" placeholder="Message" required></textarea>
</div>
<!-- form message prompt -->
<div class="row">
<div class="col-12">
<div class="contact_msg" style="display: none">
<p>Your message was sent.</p>
</div>
</div>
</div>
<div class="col-12">
<input type="submit" value="Submit Form" class="btn btn-success" name="post">
</div>
<!-- hidden reCaptcha token input -->
<input type="hidden" id="token" name="token">
</div>
</form>
</div>
</div>
</div>
</section>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('YOUR SITE KEY', {action: 'homepage'}).then(function(token) {
// console.log(token);
document.getElementById("token").value = token;
});
// refresh token every minute to prevent expiration
setInterval(function(){
grecaptcha.execute('YOUR SITE KEY', {action: 'homepage'}).then(function(token) {
console.log( 'refreshed token:', token );
document.getElementById("token").value = token;
});
}, 60000);
});
</script>
</cfif>
<!-- References for the optional jQuery function to enhance end-user prompts -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
This is how I passed the values to the API. Again, just passing along code that worked, not saying this is the only way
<cfhttp method="post" url="https://www.google.com/recaptcha/api/siteverify" result="Response">
<cfhttpparam name="secret" type="formField" value="#application.SecretKey#">
<cfhttpparam name="response" type="formField" value="#form["g-recaptcha-response"]#">
</cfhttp>
the post method is not getting the username record. the get method is working fine but html form is showing the following error:
This field is required
<h2>Users</h2>
<ul>
<form method="post" action=""><input type='hidden' name='csrfmiddlewaretoken' value='8gQo0iGRTDE7kayhFJqj2fOt7UkejlkG' />
<li>
<input type="text" value= mayur><br>
<input type="submit" value="follow" />
</li>
<li>
<input type="text" value= mayurnitrr><br>
<input type="submit" value="follow" />
</li>
<li>
<input type="text" value= lokesh><br>
<input type="submit" value="follow" />
</li>
</form>
</ul>
<p align="center">Back</p>
You haven't shown how you handle these but none of your inputs have a name parameter which you need to provide
<input type="text" name="somethingdescriptive" value="lokesh"><br>
request.POST should now contain the key "somethingdescriptive"
I have a registration page that will submit all the registration values into MS SQL database. I am trying to control the size of the image that is updated to the database to be width=125 height=125. Is there a way to control that before it is submitted into the database?
Also is this the most recent way to submit it into the database?(The most recent I could find was 2011)
FORM
<form class="m-t" role="form" action="cfm/register_process.cfm" method="post" enctype="multipart/form-data">
<div class="form-group">
<input type="text" name="employee_number" class="form-control" placeholder="Employee Number" required="">
</div>
<div class="form-group">
<input type="text" name="firstname" class="form-control" placeholder="First Name" required="">
</div>
<div class="form-group">
<input type="text" name="lastname" class="form-control" placeholder="Last Name" required="">
</div>
<div class="form-group">
<input type="text" name="department" class="form-control" placeholder="Department" required="">
</div>
<div class="form-group">
<input type="text" name="position" class="form-control" placeholder="Position" required="">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required="">
</div>
<div class="form-group">
<input type="text" name="phone_extension" class="form-control" placeholder="Extension" required="">
</div>
<div class="form-group">
<input type="text" name="user_name" class="form-control" placeholder="User ID" required="">
</div>
<div class="form-group">
<input type="password" name="user_pass" class="form-control" placeholder="Password" required="">
</div>
<div class="input-group">
<span class="input-group-btn">
<span class="btn btn-primary btn-file">
Select image
<input type="file" name="filefieldname" id="filefieldname" multiple />
</span>
</span>
<input id="filename" class="form-control" type="text"/>
<span class="input-group-btn">
<span class="btn btn-primary cleared">Reset</span>
</span>
</div>
<div class="form-group">
<div class="checkbox i-checks"><label> <input type="checkbox"><i></i> Agree the terms and policy </label></div>
</div>
<button type="submit" class="btn btn-primary block full-width m-b">Register</button>
<p class="text-muted text-center"><small>Already have an account?</small></p>
<a class="btn btn-sm btn-white btn-block" href="login.html">Login</a>
</form>
Then the form calls register_process.cfm and submits to database
<cffile action="readbinary" file="#form.filefieldname#" variable="bin_filedata">
<cfquery datasource="test" name="UserRegistration">
INSERT INTO dbo.Users (employee_number, user_name, user_pass, firstname, lastname, position, email, phone_extension, department, picture)
VALUES (
, <cfqueryparam value='#form.employee_number#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.user_name#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.user_pass#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.firstname#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.lastname#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.position#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.email#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.phone_extension#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#form.department#' cfsqltype='cf_sql_varchar' />
, <cfqueryparam value='#bin_filedata#' cfsqltype='cf_sql_blob' />
)
</cfquery>
<script>
self.location="../login.html";
</script>
Unfortunately when I try to submit this I just get an all white screen and it does not update the database. I am assuming I am doing something wrong with the picture.
I'm trying to log on onto a website with mechanize for python; however when presented with correct credentials in the form it fails to log in.
Here's what I'm doing following the mechanize tutorial:
def logon(self):
baseurl = "https://www.website.com/login"
br = mechanize.Browser(factory=mechanize.RobustFactory())
br.open(baseurl)
br.select_form(nr=0)
br.form["username"] = self.username
br.form["password"] = self.password
response = br.submit()
print response.geturl()
That should take me to the website.com/dashboard but it's saying at the website.com/login page as though it failed. I can log in manually, and everything passed through the debugger so I'm not sure what I'm doing wrong. I did some digging, and I checked through the form HTML for javascript, and the form doesn't seem to have any attached to it.
Here's the form:
<form method="post" class="login-form">
<fieldset>
<div class="row form-section">
<label for="email">Email Address</label>
<span class="input-text"><input class="required-email" type="text" id="email" value="" name="username" /><span class="required">Required Info</span></span>
<!--<input type="text" id="email" name="username" placeholder="Enter Email Address" class="text" aria-required="true" required="required" style='float:right;' size="30" value="" /><p> -->
</div>
<div class="row form-section">
<label for="pass">Password</label>
<span class="input-text"><input class="required-text" type="password" id="pass" value="" name="password" /><span class="required">Required Info</span></span>
<!--<input type="password" placeholder="Enter Password" class="text" size="30" autocomplete="off" value="" id="password" name="password" style='float:right;' aria-required="true" required="required" />-->
</div>
<div class="row row-btn">
<input type="submit" value="Log in" />
<span>Don't have an account?<br><br>Forgot your password? Didn't get your activation email?</span>
</div>
</fieldset>
<input type="hidden" value="com_oms" name="option">
<input type="hidden" value="login" name="task">
<input type="hidden" name="return" value="">
<input type="hidden" name="9402951e32acb8d73d4a6972ae540c63" value="1" />
</form>
I know there were some similar questions asked but there haven't seemed to be any clear answers that my searching has brought up. Can anyone shed some light on what is going on?
Would like to add as a comment but am not able to:
I doubt if the few hidden inputs especially the string serve as a verification to prevent CSRF attacks. Did you try submitting the hidden fields back along with email/password? That might help you out.
I have this HTML code:
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form action="http://www.aweber.com/scripts/addlead.pl" method="post">
<input id="email" class="text" type="text" size="20" value="Enter your best email" name="email" onblur="if (this.value == '') {this.value = 'Enter your best email';}" onfocus="if (this.value == 'Enter your best email') {this.value = '';}" />
<input type="hidden" name="meta_web_form_id" value="">
<input type="hidden" name="meta_split_id" value="">
<input type="hidden" name="listname" value="">
<input type="hidden" name="redirect" value="">
<input type="hidden" name="meta_adtracking" value="">
<input type="hidden" name="meta_message" value="1">
<input type="hidden" name="meta_required" value="email">
<input type="hidden" name="meta_tooltip" value="">
<div style="padding-top:5px;">
<center><input class="button1" id="submit" type="image" src="red_getwaitinglist.png" name="submit" value="Get Instant Access"/></center>
</div>
</form>
</BODY>
</HTML>
and I'm using this Function to replace the element using RegEx:
Function StripTags(ByVal html As String, ByVal replace As String) As String
Return Regex.Replace(html, "<form.+?</form>", replace)
End Function
but it doesn't seem to work. It returns the same code (no replacement).
I don't know much of regex so I'm assuming the RegEx syntax might be wrong.
Can someone help me with that or show me where I'm wrong?
Append the RegexOption Singleline. Without this . will not match newlines.
Return Regex.Replace(html, "<form.+?</form>", replace, RegexOptions.Singleline)
See RegexOptions Enumeration for more details.