FORM VALIDTION difficulty - html

I applied validation IN THIS JSP PAGE. If I leave username/password empty, I will be prompted to enter those to fields, but the PROBLEM is that after I press OK on validation prompt,the page goes to 2_control.jsp.I WANT IT TO GO TO THE NEXT PAGE ONLY IF the validation thing is ok,not otherwise.plz hlp.What change should i make?
Here is my code:
<html>
<head>
<script>
function validLogin(){
if (document.form.userName.value == ""){
alert ( "Please enter Login Name." );
document.loginform.userName.focus();
return false;
}
if (document.form.password.value == ""){
alert ( "Please enter password." );
document.userform.password.focus();
return false;
}
alert ( "Welcome User" );
return true;
}
</script>
</head>
<body>
<form name="form" method="post" action="2_control.jsp" onsubmit="return validLogin();">
<table width="250px" border=0 style="background-color:ffeeff;">
<tr><td colspan=2 align="center" style="font-weight:bold;font-size:20pt;" align="center">User Login</td>
</tr>
<tr><td colspan=2> </td>
</tr>
<tr><td style="font-size:12pt;" align="center">Login Name:</td>
<td><input type="text" name="userName" value=""></td>
</tr>
<tr><td style="font-size:12pt;" align="center">Password:</td>
<td><input type="password" name="password" value=""></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>

change document.userform.password.focus(); to document.form.userName.focus();
Change only form name when you focus on text box.. userform is wrong so your validation is not work..

<script>
function validLogin(){
if (document.form.userName.value == ""){
alert ( "Please enter Login Name." );
document.form.userName.focus();
return false;
}
else if (document.form.password.value == ""){
alert ( "Please enter password." );
document.form.password.focus();
return false;
}
}
</script>
Replace this script tag...
You do small mistake in writing form name..

Related

How to disable/ hide all buttons after one click on any button (cshtml)

i would like to know how to disable/hide all the buttons once user clicks on any of the buttons. I am only allowed to use c# or html. I have found solutions in Javascript but i cannot use it. (i did not upload my razor c# code due to lack of space)
I am creating a program that allows user to vote for any one of the candidates. Once user has clicked and chosen on one candidate, the voting result will be displayed and user should not be allowed to vote again.
<!DOCTYPE html>
<html>
<head>
<title>Elections</title>
</head>
<body>
<form id="form1" method="post">
<div>
<table>
<tr>
<td>Harry</td>
<td><input id="Harry" name="submit" type="submit" value="Vote Harry" /></td>
</tr>
<tr>
<td>John</td>
<td><input id="John" name="submit" type="submit" value="Vote John" /></td>
</tr>
<tr>
<td>Bryan</td>
<td><input id="Bryan" name="submit" type="submit" value="Vote Bryan" /></td>
</tr>
<tr>
<td>Jack</td>
<td><input id="Jack" name="submit" type="submit" value="Vote Jack" /></td>
</tr>
</table>
</div>
<div>
#if (result != "")
{
<p>#result</p>
}
<!--Ensure that user has voted before showing the vote results-->
#if (voteCheck == true)
{
<p>Total Votes: #Session["totalVotes"]</p> <!--using session allows values to be kept even after button click-->
<p> Harry: #Session["Harry"]</p>
<p> John: #Session["John"]</p>
<p> Bryan: #Session["Bryan"]</p>
<p> Jack: #Session["Jack"]</p>
}
</div>
</form>
</body>
</html>
You need an action attribute to the form action="youraction/controller here"
And in youraction you write some C# code return list of display value ("none" or "")
And in cshtml you add style="display:#display"
<input id="Harry" name="submit" type="submit" style="display:#display" value="Vote Harry" />
You could simply add a Ternary operator that check the session object and sets the disabled property accordingly.
<input id="Harry" #(Session["Harry"] != null ? "disabled" : "") name="submit" type="submit" value="Vote Harry" />

HTML code for button click limitation

This is my code, and it's for SMS spoofing service. I need a system, which will control how many SMS messages can user send. For example every user has 5 messages to send, and all above 5 is forbiden.
I need you to help me to make a simple HTML code, which will show me the message like "It's enough" when they click submit button more then 5 times.
<tr>
<td>Password:</td>
<td><input type="password" name="pass" placeholder="toro"></td>
</tr>
<tr>
<td>To: </td>
<td><input type="text" name="to" size="30" placeholder="+38164,+38162 etc..." /></td>
</tr>
<tr>
<td>From: </td>
<td><input type="text" name="from" size="30" placeholder="Facebook, 911 etc... " /></td>
<tr>
<td>Message: </td>
<td><textarea name="message"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" /></td>
<tr>
Not possible with HTML. Can be done with jquery or javascript as below. But my suggestion would be to have a counter in server side. Because, if the page is refreshed, the counter would be reset and again SMS would be able to be sent for another 5 more times and the cycle continues.. This is not proper restriction to have only client side check.
<script>
var clickcount = 0;
var maxlimit = 5;
$(document).ready(function() {
$("#btnSubmit").click(function(){
if (clickcount >=maxlimit)
{
alert ("Sorry, You have used your max limit of "+maxlimit+" sms for the day ");
}
else if ($("#formID").valid())
{
clickcount++;
$("#formID").submit();
}
});
});
</script>

Contact form doesnt send email, Error page

Hi I really need help with this.
I have just finished a design for a client and her website went live on Thursday, however the contact form doesn't work. I do know things about HTML/CSS but I am very basic with stuff with script. When you fill in the form and press send a 'not found' page appears.
Whats gone wrong?
I have tried looking at other posts about this kind of thing but I think the code needs looking at.
Much appreciated
//email form validation
function everif(str) {
var at="#"
var punct="."
var lat=str.indexOf(at)
var lstr=str.length
var lpunct=str.indexOf(punct)
if (str.indexOf(at)==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct)==-1 || str.indexOf(punct)==0 || str.indexOf(punct)==lstr){
alert("Valid email must be entered")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Valid email must be entered")
return false
}
if (str.substring(lat-1,lat)==punct || str.substring(lat+1,lat+2)==punct){
alert("Valid email must be entered")
return false
}
if (str.indexOf(punct,(lat+2))==-1){
alert("Valid email must be entered")
return false
}
if (str.indexOf(" ")!=-1){
alert("Valid email must be entered")
return false
}
return true
}
function evalid(){
var emailID=document.contact_form.mail
if (everif(emailID.value)==false){
emailID.focus()
return false
}
//empty field validation
var fname=document.contact_form.fname
if ((fname.value==null)||(fname.value=="")){
alert("Fields marqued with * must be entered")
fname.focus()
return false
}
var lname=document.contact_form.lname
if ((lname.value==null)||(lname.value=="")){
alert("Fields marqued with * must be entered")
lname.focus()
return false
}
var message=document.contact_form.message
if ((message.value==null)||(message.value=="")){
alert("Fields marqued with * must be entered")
message.focus()
return false
}
return true
}
</script>
<form name="contact_form" method="post" action="mailer.php" onSubmit="return evalid()">
<table border="0"><tr>
<td colspan="2"><input name="fname" type="text" value="First Name" size="40" /></td>
</tr><tr>
<td colspan="2"><input name="lname" type="text" value="Last Name" size="40" /></td>
</tr><tr>
<td colspan="2"><input type="text" value="Email" name="mail" size="40" /></td>
</tr><tr>
<td colspan="2"><textarea name="message" value="Your Message" onkeyup="return limitarelungime(this, 255)" cols="35" rows="5"></textarea></td>
</tr><tr>
<td></td>
<td colspan="2"></td>
</tr>
<tr>
<td align="right">
<input type="image" src="images/send.png" value="Submit" alt="submit" name="submit"/>
</td>
<td align="right"><alt="Valid Contact Form" width="20" height="20" border="0" /></a></td>
</tr>
</table>
</form>
</div>
Page not found error suggests that there is some problem with the URL redirect quite simply or the file does not exist. In your case if the form is sending the data to a mailer.php script, just make sure that the path of the file is entered correctly and that the file is there in a particular folder according to the path. Your problem should be solved.

Why can't I submit my form with WWW::Mechanize::Firefox in Perl?

I have an HTML this is part of the form I'm working on
<form action="/goform/FormUpdateVAP" autocomplete="off" name="myform" id="formid" method="POST">
<table>
<tbody>
<tr>
<td align="right"><span class="label">Name:</span></td>
<td><input id="essid" name="essid" value="X" type="text"></td>
</tr>
<tr>
<td align="right"><input id="broadcast_essid" name="broadcast_essid" value="any" checked="" type="checkbox"></td>
<td><span class="label">Broadcast name:</span></td>
</tr>
</tbody>
</table>
<!-- BEGIN RIGHT COLUMN -->
<table>
<tbody><tr>
<td>
<input name="authentication" id="authentication" value="any" onclick="Update();" type="checkbox"><span class="label"><b>authentication</b></span>
</td>
<td>
<input onclick="Update();" name="wp" id="wp" value="any" type="checkbox"><span class="label"><b>Wp</b></span>
<select id="8021x_mode" name="8021x_mode" onchange="Update();"><option value="wpa">WPA</option>
<option value="wep">WEP</option>
</select>
</td>
</tr>
<tr>
<td height="26">
<input onclick="Update();" name="w_p" id="w_p" value="any" type="checkbox"><span class="label"><b>Wp</b></span>
<select id="8021x_mode" name="8021x_mode" onchange="Update();"><option value="wpa">WPA</option>
<option value="wep">WEP</option>
</select>
</td>
</tr>
<tr>
<td>
<input id="cancel" name="cancel" value="Cancel" onclick="window.location.href = '/fg/list.asp';" type="button">
</td>
<td>
<input id="add-2" name="add" value="Save" type="submit">
</td>
</tr>
</tbody>
</table>
I'm trying to submit it filling the Name and the Broadcast name. And checking the 8021x_mode and the wp checkboxes. If I tick 8021x_mode and set the fields the form submits just fine. But when I try ticking wp it doesn't submit. I got no error messages.
Here's my code so far:
use WWW::Mechanize::Firefox;
use Crypt::SSLeay;
use URI::Fetch;
use HTML::TagParser;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; #not verifying certificate
my $url = 'https://';
$url = $url.#ARGV[0];
my $mech = WWW::Mechanize::Firefox->new;
$mech->get($url);
$mech->form_id('formid');
$mech->tick( '8021x_mode','any');
$mech->tick( 'wp','any'); --after I add this the form doesn't submit
my $name = #ARGV[1];
$mech->set_fields(
'vap_name' => $name,
'essid' => $name,
);
$mech->click_button( id => 'add-2' );
$mech->reload();
add-2 is the submit button. Any idea why is not working? If you need more information please let me now. Any help will be highly appreciated.
The problem is that the html doesn't contains the choice any for 8021x_mode.
I get this error :
No elements found for Checkbox with name '8021x_mode' and value 'any'
at test.pl line 24.
To check the form, I recommend you the mech-dump utility (installed with WWW::Mechanize)
$ mech-dump --forms http://domain.tld/path_to_forms
POST /goform/FormUpdateVAP [myform]
essid=X (text)
broadcast_essid=<UNDEF> (checkbox) [*<UNDEF>/off|any]
authentication=<UNDEF> (checkbox) [*<UNDEF>/off|any/authentication]
wp=<UNDEF> (checkbox) [*<UNDEF>/off|any/Wp]
8021x_mode=wpa (option) [*wpa/WPA|wep/WEP]
w_p=<UNDEF> (checkbox) [*<UNDEF>/off|any/Wp]
8021x_mode=wpa (option) [*wpa/WPA|wep/WEP]
cancel=Cancel (button)
add=Save (submit)
As you can see, there's no any choice...
Maybe the javascript there is doing some things that we don't know.
A workaround is to use LiveHttpHeaders Firefox addon to catch the forms POSTed to /goform/FormUpdateVAP and then instead of ticking, do a POST request with WWW::Mechanize.

Why i am getting Undefined index?

i am developing an application using CodeIgniter. In my application when i submit the form in firefox 10.0, i got this error
Message: Undefined index: adcopy_response
But when i submits the form in IE 9. It's working fine my application. No errors found in IE. Can any one. My HTML code is
<table>
<form action="" method="post">
<tr id="row">
<td><b>Title:</b></td>
<td>
<input type="text" style="width:450px;" name="title" value="" />
</td>
</tr>
<tr id="row">
<td><b>Description:</b></td>
<td>
<textarea style="width:450px;" name="desc" cols="35" rows="10"></textarea>
</td>
</tr>
<tr id="row">
<td><b>URL:</b></td>
<td>
<input type="text" style="width:450px;" name="url" value="" />
</td>
</tr>
<tr id="row">
<td><b>Category:</b></td>
<td>
<select name="cat">
<option value="">Select Category</option>
<option value="ajax-tutorials">AJAX Tutorials</option><option value="asp-tutorials">ASP Tutorials</option><option value="asp.net-tutorials">ASP.NET Tutorials</option><option value="codeigniter-tutorials">CodeIgniter Tutorials</option><option value="css-tutorials">CSS Tutorials</option><option value="html-tutorials">HTML Tutorials</option><option value="javascript-tutorials">JavaScript Tutorials</option><option value="jquery-tutorials">jQuery Tutorials</option><option value="ms-sql-tutorials">Ms SQL Tutorials</option><option value="mysql-tutorials">MySQL Tutorials</option><option value="php-tutorials">PHP Tutorials</option><option value="programming-tutorials">Programming Tutorials</option><option value="wordpress-themes">Wordpress Themes</option><option value="wordpress-tutorials">WordPress Tutorials</option><option value="xml-tutorials">XML Tutorials</option> </select>
</td>
</tr>
<tr id="row">
<td><b>Prove you're not a robot</b></td>
<td>
<script type="text/javascript" src="http://api.solvemedia.com/papi/challenge.script?k=hse4RWPEOMayq3QzRQiUZTnTtVkI8Jmf"></script>
<noscript>
<iframe src="http://api.solvemedia.com/papi/challenge.noscript?k=XXXX" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="adcopy_challenge" rows="3" cols="40"></textarea>
<input type="hidden" name="adcopy_response" value="manual_challenge"/>
</noscript> </td>
</tr>
<tr id="row">
<td>
<input type="hidden" name="ok" value="1" />
<input type="hidden" name="by" value="seekphp" />
<input type="submit" name="submit" value="Submit Tutorial" />
</td>
</tr>
</form>
</table>
and CI code is
function submit(){
$privkey="XXXX";
$hashkey="XXXX";
$data['err'] = "";
$this->form_validation->set_rules('title', 'Title', 'required|trim|xss_clean|htmlentities');
$this->form_validation->set_rules('desc', 'Description', 'required|trim|xss_clean|htmlentities');
$this->form_validation->set_rules('url', 'URL', 'required|trim|xss_clean');
$this->form_validation->set_rules('cat', 'Category', 'required|trim|xss_clean');
if($this->form_validation->run() == FALSE){
} else {
$title = $this->input->post('title');
$desc = $this->input->post('desc');
$url = $this->input->post('url');
$cat = $this->input->post('cat');
$by = $this->input->post('by');
$ok = $this->input->post('ok');
$solvemedia_response = $this->Captcha_model->solvemedia_check_answer($privkey,
$_SERVER["REMOTE_ADDR"],
$_POST["adcopy_challenge"],
$_POST["adcopy_response"],
$hashkey);
if ($solvemedia_response->is_valid) {
if($this->Tutorial_model->add_tut($title, $desc, $url, $cat, $by, $ok) == TRUE){
$this->session->set_flashdata('msg', "Tutorial has been added successfully.");
redirect(base_url().'user/submit', 'refresh');
} else {
$this->session->set_flashdata('err', "Tutorial may already exist or there is an error while submitting tutorial.");
redirect(base_url().'user/submit', 'refresh');
}
} else {
$data['err'] = "Incorrect Captcha.";
}
}
$data['cats'] = $this->Category_model->get_all_cats();
$this->load->view("user/submit_view", $data);
}
and when i print_r($_POST);
i got the following
Array ( [title] => test title [desc] => test desc [url] => test url [cat] => javascript-tutorials [adcopy_challenge] => 2#hse4RWPEOMayq3QzRQiUZTnTtVkI8Jmf#Szx1Cc29gNUENU8bgrSwY39APTC4lJjoCYJjyXvIJi2gPnq5tZIMpr0JgoGocL4bVHKrYt6Zyx3w-DAv2nYsjYiaeT-0C9Ec297zPussZKqXHDAdWTWT7ZcC1MklNV75-TPQzGDGu0yUgkDQWcRup.sNAOGBvK0cXCac1RzQ7T6adyI4bmcrNTpt7ANEEq2-1QcBgS8Uky6FxFHeFyGMDgzlJvqGyrBJfDRBNwroHBUXGHC1Jza9b54IS1.0E9kwlqZUOeBX9EomSEVcgrS6gA [ok] => 1 [by] => seekphp [submit] => Submit Tutorial ) 1
Even if you think you know what should be in the $_POST array, don't assume it if you want to avoid notices. Codeigniter has the Input class to make this easier:
$_POST['doesnt exist']; // generates undefined index notice
$this->input->post('doesnt exist'); // returns FALSE, no notice
Most importantly, you have the input in a <noscript> tag, so the browser may not send the value.
But when I submit the form in IE9 it's working fine, no errors found.
Chances are you either have javascript turned off, or IE is misbehaving (quite likely).
I think $_POST["adcopy_response"] is being used on Captcha Model but it is not in $_POST
Finally i resolved the problem by removing <table> <tr> <td> tags
Place your hidden tag out of <noscript> tag. only When script is disabled in your browser, code inside the <noscript> will work. Disable script in your browser and then run it will perfectly work.