Passing variables from PHP to Perl using POST - html

This one is a tad frustrating.
If I run this perl script ...
#!/usr/bin/perl
use CGI qw/:standard/; # load standard CGI routines
my $query = new CGI;
my $club5 = $query->param('club5');
my $messagetext = $query->param('messagetext');
print header, # create HTTP header
start_html('Hello World'), # start of HTML
h1('Hello World'), # level 1 headers
h1($club5),
h1($messagetext),
end_html; # end of HTML
1;
from a remote Chrome browser with
http://www.<hostname>/cgi-bin/message_test.pl?club5=coop9&messagetext=test
the correct page is produced. But if I then execute this PHP program ...
<?php
$user_id = "10006";
echo <<<END
<html>
<head>
<title>Send Message</title>
</head>
<BODY bgcolor="#e8e8e8">
<br>
<table width="450px" height="150px" align="center" valign="top" bgcolor="#e8e8e8">
<form action="http://<hostname>/cgi-bin/message_test.pl" method="post">
<INPUT TYPE="hidden" NAME="user_id" VALUE="$user_id">
<tr align="center" valign="top">
<td>
<br>
<font face="Verdana" size="2">
<input name="messagetext" type="text" size="64">
<br>
<br>
<br><center>
<input name="submit" type="submit" value="SEND">
</font>
</td>
</tr>
</form>
</table>
</body>
</html>
END;
?>
from the same browser with
http://<hostname>/message_test.php
nothing is returned. I swear I had something similar this running a year ago. Is there something new I should be aware of when passing (hidden) variables to Perl using HTTP POST?

It's failing because your browser incorrectly guesses what you meant by your invalid HTML.
It worked after I changed
<table ...>
<form ...>
<INPUT TYPE="hidden" NAME="user_id" VALUE="$user_id">
...
</form>
</table>
to
<form ...>
<INPUT TYPE="hidden" NAME="user_id" VALUE="$user_id">
<table ...>
...
</table>
</form>

In PHP, shouldn't
<INPUT TYPE="hidden" NAME="user_id" VALUE="$user_id">
be
<INPUT TYPE="hidden" NAME="user_id" VALUE="<? echo $user_id; >">
?

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" />

XSS attack on JSP how prevent

I have read a lot about the XSS attack and now I understood how it works then now I am trying to validate it. However I am having some problems :
Looking for many foruns I did :
1 - Download of jar jstl-1.2
2 - On .jsp page I have added :
taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"
And in the field that I am having problem I put the XMLSCAPE - so I would like to know if is the correct format :
<div class="ibm-container">
<div class="ibm-container-body">
<form action="order_status" class="ibm-column-form ibm-styled-form" method="post">
<p><label for="customer">Customer number:</label>
<span><input name="customer" id="customer" maxlength="7" value="${fn:escapeXml(customer)}" type="text" /></span></p>
<div class="ibm-buttons-row">
<table border="0px" cellpadding="0px" cellspacing="0px">
<tr>
<td width="180px"></td>
<td>
<p><input name="submit" value="<%=com.ibm.ssos.Constants.TEXT_GET_ORDERS%>" type="submit" class="ibm-btn-pri ibm-btn-small" />
<input name="action" value="<%=com.ibm.ssos.Constants.TEXT_GET_ORDERS%>" type="hidden" /></p>

How to use value from input tag in the same form

I am looking how to reuse the value="typed_from_user" into another tag in the same formulary without using js, just PHP & HTML.
Is it even possible?
For example, here i want to reuse the word 'pizza'
<form>
<input name="hello" type="text" value="I want pizza">
<input name="order" type="text" value="pizza">
</form>
maybe something storing it in a variable?
<form>
<input name="hello" type="text" value="<?php echo $whatyouwant ;?>">
<input name="lunch" type="text" value="<?php echo substr($whatyouwant,7,5);?>"><!--cut it from letter 7, the word pizza-->
<input name="order" type="submit" value="submit">
</form>
yeah, supouse that we know where exactly starts the word pizza
This are the files i am using as tests
action.php
form.php
<?php
//action.php
$var = $_POST['hello'];
$var_lunch= $_POST['lunch'];
echo "hello: $var<br>";
echo "lunch: $var_lunch<br>";
?>
file form.php:
<html>
<header>
<title>test-page</title>
<!--bootstrap-->
<link rel="stylesheet" type="text/css" href="../../../css/bootstrap/bootstrap_v4.0.0.css">
</header>
<body>
<?php
$whatyouwant=777;
?>
<form method="post" action="action.php">
<input name="hello" type="text" value="<?php echo $whatyouwant ;?>">
<input name="lunch" type="text" value="<?php echo substr($whatyouwant,7,5);?>">
<input name="order" type="submit" value="submit">
</form>
</body>
</html>
OUTPUT:
hello: i want pizza
lunch:
If you are trying to get the input value form one text field to another text field only using PhP and HTML, I have to say that it is quite impossible. PhP is the server side language so to get the value from one field to another, it must first reach the server and then it display but will show error in PhP.
To achieve this, you have to use JS. You can achieve this from just a few lines of code using jQuery.

How to make a suggestion box

I am trying to make a suggestion box so that way I can see what my viewers think would make my site better. Here is some code that I have.
<form id="form1" name="form1" method="post" action="">
<label>
<textarea name="input" id="input" cols="45" rows="5"></textarea>
</label>
</form>
<form id="form2" name="form2" method="post" action="">
<label>
<input type="submit" name="export" id="export" value="Submit" />
</label>
</form>`
But this is all I have. It seems to work client side but not server side. Can someone tell me what language and if you know the code that I would have to use that would be great.
Post to another HTML file action="myformresults.html"
Post to a server side scripting language like PHP action="myphpformresult.php" which will 'do things' and then render an HTML document or any other thing (like send as email).
You can call a Javascript function to handle the form.
I would recommend PHP.
You can access a post variable in PHP by name:
HTML <input name="postVar">
PHP $myVar = $_POST['postVar'];
all you need is writing a jquery code as follows in your html file: //note that i rewrite your html code as no need for two forms
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
function submitters(){
event.preventDefault();
$.post( "mail.php.txt", $( "#form1" ).serialize(),function( data ) {
$("#formcontainer").fadeOut("slow");
$("#formcontainer").html(data);
} );
}
</script>
</head>
<body>
<div id="formcontainer">
<form id="form1" name="form1" method="post" action="">
<label>
<textarea name="input" id="input" cols="45" rows="5"></textarea>
</label>
<input Onclick="submitters()" type="button" name="export" id="export" value="Submit" />
</form>
</div>
</body>
</html>
then in mail.php file something like
<?php
$input=$_POST['input'];
$to = 'youremail#domain.com';
$subject = 'the subject';
$message = $input;
$headers = 'From: website.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

HTML5 File text disappears from textarea almost immediately when I OK alert

The HTML below seems to successfully reads a text file from client PC and display it in textarea. However it is immediately blanked in Firefox and fails completely in Chrome. No idea what happens in IE as I dont have a copy.
First browse(Firefox) or Choose(Chrome); Then click "Load CAD Data"
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8;" />
<title>miCAD 0.00 </title>
<script type="text/javascript"><!--
"use strict";
function loadCadFile(){
var fileName=document.getElementById('fileName').files[0];
var fileReader=new FileReader();
fileReader.onload=function(e){
var textFromCadFile=e.target.result;
var el=document.getElementById('CADdata');
el.style.display='block';
el.innerHTML=textFromCadFile;
};
fileReader.onerror=function(e){
alert('read error');};
fileReader.readAsText(fileName,"UTF-8");
alert('xxx');
}
//--></script>
</head><body>
<form name="f" action="" method="post" >
<p>CAD file selector</p>
<table class="tc">
<tr><td colspan="2"><input type="file" id="fileName" /></td></tr>
<tr><td></td><td class="right">
<button onclick="loadCadFile(); alert('yyy');">Load CAD data</button></td></tr>
</table>
<textarea id="CADdata" width="90%" rows="10"></textarea>
<input type="hidden" name="MAX_FILE_SIZE" value="40000" />
<input type="submit" value="just in case">
</form>
</body></html>
Example code is at "mips-erp.com/CAD/test.html as the above is my best attempt at pasting and then aligning the code
You don't use innerHTML to set the content of a text area you use value
el.value=textFromCadFile;
I recoded it. Working code follows:
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8;" />
<title>miCAD 0.00 </title>
<script type="text/javascript"><!--
"use strict";
function loadCadFile(fileData){
var fileReader=new FileReader();
fileReader.onload=function(e){
document.getElementById('CADdata').value=e.target.result;
};
fileReader.readAsText(fileData.files[0]);
}
//--></script>
</head><body>
<form name="f" action="" method="post" >
<p>CAD file selector</p>
<table class="tc">
<tr><td colspan="2"><input type="file" id="fileName" onchange="loadCadFile(this)" /></td></tr>
</table>
<textarea id="CADdata" width="90%" rows="10"></textarea>
<input type="hidden" name="MAX_FILE_SIZE" value="40000" />
</form>
</body></html>