How to execute some code before posting a form using classic ASP - forms

Using classic ASP, I want to execute some code before submitting to a form, below is my code.
I am trying to store login credentials into cookies before posting the form to another page.
Please note that I am posting to an ASP.NET page that is held in a separate domain.
Another example, just to make this clearer. Let's say I want to validate fields before posting without using JavaScript.
<%
dim uname
uname= Request.Cookies("username")
%>
<FORM action="httppost_login.aspx" METHOD ="post" >
<br />Username: <INPUT NAME ="username" SIZE ="30" maxlength="15" value="<% if uname <>"" then response.write(uname) %>" />
<br />Password: <INPUT NAME ="password" SIZE ="30" type=password maxlength="20" />
<br />
<INPUT TYPE ="SUBMIT" value="Login" name="btnSubmit" />
<input type="checkbox" name="remember" value="Remember my username" <%if uname <> "" then Response.Write("checked")%> />Remember my username
</FORM>
<%
If Request.Form("btnSubmit") <> "" Then
uname=Request.Form("username")
dim rememberme
rememberme = request.form("remember")
if rememberme <> "" and uname <> "" then
Response.Cookies("username") = uname
Response.Cookies("username").Expires = Date() + 30
end if
end if
%>

You can't run code easilly after the submit button is pressed.
This comes down to design. Your form action is:
httppost_login.aspx
The 'standard' way of achieving what you want is by having code on that page which handles the cookies/anything else.
I would usually give the form action a querystring:
<FORM action="httppost_login.aspx?action=login" METHOD ="post" >
Then on that page, have:
Dim strPageAction
strPageAction = request.querystring("action")
if(strPageAction = "login" then
'Put your cookie code here, request.form("username") etc will still work!
end if

yes, a redirect page can post to a third party page using xmlhttp

Related

Recaptcha replaces Formmail's "email" (From) field with my server address. Without Recaptcha, From field works fine. Why?

I've been using Tectite Formmail.php for many years. Finally added Recaptcha ver 2 (Invisible mode). It works okay, except that it messes with the derive_fields email string. Without Captcha, the results email's From field properly contains the name and email address of the person who filled out my form, that is a value derived from "realname" and "email".
e.g., Ralph Waldo <rwaldoexample#gmail.com
When I enable ReCaptcha, the results email's From field undesirably shows my hosting account username and server address:
e.g., *username#1a2b3c45.prod.phx1.example.net
If I revert the form to a standard tag and disable Recaptcha (by nulling the $REQUIRE_CAPTCHA and $RECAPTCHA_PRIVATE_KEY values as in code shown below), I get the desired From contents as I used to. This behavior is the same for Formmail v 9.15 and 9.19.
If this is standard procedure for Recaptcha, it seems undocumented. If not, what's the fix?
SNIPPETS, PER REQUEST:
In web page header:
<!-- CAPTCHA Ver2 Invisible -->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("Contact_Form").submit();
}
</script>
<!-- end CAPTCHA -->
In web page HTML
<form id="Contact_Form" action="https://www.example.com/formmail.php" method="post" name="Formtype 1">
<input name="good_url" value="https://www.example.com/tnxpg.html" type="hidden" />
<INPUT NAME="subject" TYPE="hidden" VALUE="~~FORM RECEIVED - Main mail form">
<!-- OTHER INFO TO APPEAR IN EMAIL -->
<input type="hidden" name="form_version" value="Visitor used Main Form">
<input type="hidden" name="mail_options" value="FromAddr=formmssg1#example.com" />
<!-- DON'T CHANGE THE FOLLOWING ... EXCEPT put actual field names after equals signs. -->
<!-- this derives (creates) "email" and "realname" special fields from the input fields -->
<input type="hidden" name="derive_fields" value="email=EmailAddr,realname=FullName" />
<!-- DON'T CHANGE THE FOLLOWING! -->
<!-- this excludes the "email" and "realname" special fields from the body of the email you receive -->
<input type="hidden" name="mail_options" value="Exclude=email;realname" >
<input name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER" type="hidden" />
* * *
<input type="hidden" name="derive_fields" value="imgverify=g-recaptcha-response" />
<!-- with this simple Submit tag and the private key removed from Formmail.php, results email From is correct -->
<!--
<input type="submit" value=" Send message ">
-->
<input type="submit" value=" Send Message " class="g-recaptcha" data-callback="onSubmit" data-sitekey="PublicKeyGoesHere" / >
In formmail.php:
/* Help: http://www.tectite.com/fmdoc/require_captcha.php */
//// DO NOT USE CAPTCHA
//// $REQUIRE_CAPTCHA = ""; /* set to a message string if your forms */
//// USE CAPTCHA
$REQUIRE_CAPTCHA = "Confirm you are not a robot.";
/* set to a message string if your forms must provide a CAPTCHA string*/
/* Help: http://www.tectite.com/fmdoc/recaptcha_private_key.php */
//// DO NOT USE CAPTCHA
//$RECAPTCHA_PRIVATE_KEY = "";
//// USE CAPTCHA
$RECAPTCHA_PRIVATE_KEY = "myprivatekeygoeshere";
This is unusual behaviour.
I suspect there's a syntax error in your HTML and that's causing the damage to the form submission.
You should validate your HTML at https://validator.w3.org/

Search from with select option for which domain

I have a mediawiki multi language site (on sub domains) and I am trying to set up a start page similar to wikipedia, where a user can enter a search term, and then select their language from a select list.
I have no idea where to start, not much experience building forms, So with this question I am at least looking for clues and directions to go.
My idea is a simple search form, and depending on which language was selected, when a user submits, it goes to the url (related to the select list), and appends the searched term.
A simple form to get you started (the form allows you to input an URL and select a language)
function myFunction() {
// get input form values
var url = document.getElementById("iUrl").value;
var langEl = document.getElementById("iLang");
var iLang = langEl[langEl.selectedIndex].value;
console.log("URL = ", url);
console.log("Lang = ", iLang);
window.open(url + "&lr=" + iLang);
}
<form id="form" action="javascript:myFunction();">
<input size="35" type="text" id="iUrl" name="text" value="https://www.google.com/search?as_q=" />
<br>
<select name="language" id="iLang">
<option value="lang_en">EN</option>
<option value="lang_es">ES</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>

How do I get the form submit alert to cancel form action?

I have a javascript function that checks if someone entered their email:
function formValidate(){
form1 = document.forms['_register1'];
if (form1.elements['email'].value == 'Type Your Email Address Here')
{
alert('Please enter your email address.');
form1.elements['email'].focus();
return false;
}
}
Here is the form html:
<form method="post" enctype="multipart/form-data" name="_register1" id="_register" action="signup.php" >
<input type="text" class="field" value="Type Your Email Address Here" name="email" title="Type Your Email Address Here" />
<input type="submit" class="button button-signup" value="SIGN UP!" onclick="formValidate();" />
If the user has not entered an email address, I want the javascript alert to popup and once the user presses ok, I want the page to stay the same. I don't want the action="signup.php" to happen until the email is valid. This seems like it should be simple but I've looked all over the internet and can't find a solution.
Thanks.
http://www.html-form-guide.com/php-form/php-login-form.html
this might be what you're looking for.
I finally figured out the answer. The key is to use the javascript submit() function. Rather than use an input type submit, I use just a regular button. Then, after javascript validates the form and the form has the proper data, I used the submit function. Here is my code below. If anyone is curious, feel free to ask me about it.
function formValidate(){
//define form1 as registration form
form1 = document.forms['_register1'];
var submission = true;
//make sure email address is not blank
if (form1.elements['email'].value == 'Type Your Email Address Here') {
alert('Please enter your email address.');
form1.elements['email'].focus();
var submission = false;
}
//submit form if data is good
if(submission != false){
form1.submit();
}
}
And here is the html:
<input type="text" value="Type Your Email Address Here" name="email" title="Enter email" />
<input type="button" value="SIGN UP!" onclick="formValidation();" />

Could not find installable ISAM

I want to create a search function in my webpage with first
<form id="form1" name="form1" method="get" action="mySearchResults.asp">
<label>Enter Keywords:`
<input type="text" name="searchTerm" />`
</label>`
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
Then
<%
'open the connection
Dim Connect, myRecordSet
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Database='SVCS.mdb'"
%>
<%
'collect the form input
searchInput = Request.QueryString("searchTerm")`
'check for a match
Set myRecordSet = Connect.Execute ("SELECT * FROM Inventory WHERE myColumn LIKE '%" & searchInput & "%'")
'display the results
if myRecordSet.EOF then
response.write("You searched for: " & searchInput & "<br>")
response.write("A match was not found.<br>Sorry try again.")
else
response.write("You searched for: " & searchInput & "<br>")
response.write("The record was found!<br>The match is: " & myRecordSet("myColumn"))
end if
%>
<br><br>
Try Again
And the error is
Microsoft JET Database Engine error '80004005'
Could not find installable ISAM.
/sarah lee video club website/mySearchResults.asp, line 5
Please tell me how to solve this
You should not quote the database name for one thing, it is Data Source, not Database, and you do not need the equals with Open.
Set con = Server.CreateObject("ADODB.Connection")
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=SVCS.mdb"
See also http://connectionstrings.com

changing the language of error message in required field in html5 contact form

I am trying to change the language of the error message in the html5 form field.
I have this code:
<input type="text" name="company_name" oninvalid="setCustomValidity('Lütfen işaretli yerleri doldurunuz')" required />
but on submit, even the field is not blank, I still get the error message.
I tried with <input type="text" name="company_name" setCustomValidity('Lütfen işaretli yerleri doldurunuz') required />
but then the english message is displayed. Anyone know how can I display the error message on other language?
Regards,Zoran
setCustomValidity's purpose is not just to set the validation message, it itself marks the field as invalid. It allows you to write custom validation checks which aren't natively supported.
You have two possible ways to set a custom message, an easy one that does not involve Javascript and one that does.
The easiest way is to simply use the title attribute on the input element - its content is displayed together with the standard browser message.
<input type="text" required title="Lütfen işaretli yerleri doldurunuz" />
If you want only your custom message to be displayed, a bit of Javascript is required. I have provided both examples for you in this fiddle.
your forget this in oninvalid, change your code with this:
oninvalid="this.setCustomValidity('Lütfen işaretli yerleri doldurunuz')"
<form><input type="text" name="company_name" oninvalid="this.setCustomValidity('Lütfen işaretli yerleri doldurunuz')" required /><input type="submit">
</form>
HTML:
<form id="myform">
<input id="email" oninvalid="InvalidMsg(this);" name="email" oninput="InvalidMsg(this);" type="email" required="required" />
<input type="submit" />
</form>
JAVASCRIPT :
function InvalidMsg(textbox) {
if (textbox.value == '') {
textbox.setCustomValidity('Lütfen işaretli yerleri doldurunuz');
}
else if (textbox.validity.typeMismatch){
textbox.setCustomValidity('Lütfen işaretli yere geçerli bir email adresi yazınız.');
}
else {
textbox.setCustomValidity('');
}
return true;
}
Demo :
http://jsfiddle.net/patelriki13/Sqq8e/4
This work for me.
<input oninvalid="this.setCustomValidity('custom text on invalid')" onchange="this.setCustomValidity('')" required>
onchange is a must!
I know this is an old post but i want to share my experience.
HTML:
<input type="text" placeholder="Username or E-Mail" required data-required-message="E-Mail or Username is Required!">
Javascript (jQuery):
$('input[required]').on('invalid', function() {
this.setCustomValidity($(this).data("required-message"));
});
This is a very simple sample. I hope this can help to anyone.
TLDR: Usually, you don't need to change the validation message but if you do use this:
<input
oninvalid="this.setCustomValidity('Your custom message / 您的自定义信息')"
oninput="this.setCustomValidity('')"
required="required"
type="text"
name="text"
>
The validation messages are coming from your browser and if your browser is in English the message will be in English, if the browser is in French the message will be in French and so on.
If you an input for which the default validation messages doesn't work for you, the easiest solution is to provide your custom message to setCustomValidity as a parameter.
...
oninvalid="this.setCustomValidity('Your custom message / 您的自定义信息')"
...
This is a native input's method which overwrites the default message. But now we have one problem, once the validation is triggered, the message will keep showing while the user is typing. So to stop the message from showing you can set the validity message to empty string using the oninput attribute.
...
oninput="this.setCustomValidity('')"
...
//Dynamic custome validation on all fields
//add validate-msg attr to all inputs
//add this js code
$("form :input").each(function(){
var input = $(this);
var msg = input.attr('validate-msg');
input.on('change invalid input', function(){
input[0].setCustomValidity('');
if(!(input[0].validity.tooLong || input[0].validity.tooShort)){
if (! input[0].validity.valid) {
input[0].setCustomValidity(msg);
}
}
});
});
<input type="text" id="inputName" placeholder="Enter name" required oninvalid="this.setCustomValidity('Your Message')" oninput="this.setCustomValidity('') />
this can help you even more better, Fast, Convenient & Easiest.
For the lost souls who are seeking a way to fully localize their error messages, see the snippet below. In short, you have to switch over the properties of event.target.validity and override the corresponding error message using event.target.setCustomValidity(message). If you just care about the empty field case as OP, just consider the case of valueMissing.
Note that the handler is passed in the React way, but other answers already covered how to do it in vanilla JS.
For the meaning of each validity state and how to implement customized error messages, see MDN: Validating forms using JavaScript.
const handleInvalidForm = (event) => {
const { patternMismatch,
tooLong,
tooShort,
rangeOverflow,
rangeUnderflow,
typeMismatch,
valid,
valueMissing } = event.target.validity;
if (patternMismatch)
event.target.setCustomValidity('...');
else if (tooLong)
event.target.setCustomValidity('...');
else if (tooShort)
event.target.setCustomValidity('...');
else if (rangeOverflow)
event.target.setCustomValidity('...');
else if (rangeUnderflow)
event.target.setCustomValidity('...');
else if (typeMismatch)
event.target.setCustomValidity('...');
else if (valid)
event.target.setCustomValidity('...');
else if (valueMissing)
event.target.setCustomValidity('...');
}
// ...
<form onSubmit={handleFormSubmit}
onInvalid={handleInvalidForm}
>
{emailTextField}
{passwordTextField}
{signInButton}
</form>
<input type="text" id="inputName" placeholder="Enter name" required oninvalid="this.setCustomValidity('Please Enter your first name')" >
this can help you even more better, Fast, Convenient & Easiest.
Do it using JS. Grab the class of the error message, and change it's content for whereever it appears.
var myClasses = document.getElementsByClassName("wpcf7-not-valid-tip");
for (var i = 0; i < myClasses.length; i++) {
myClasses[i].innerHTML = "Bitte füllen Sie das Pflichtfeld aus.";
}
<form>
<input
type="text"
name="company_name"
oninvalid="this.setCustomValidity('Lütfen işaretli yerleri doldurunuz')"
required
/><input type="submit" />
</form>