Python Mechanize upload - javascript

Hi I have been using mechanize and python to try and upload a file to a website, so far Ive been succesfull but im stuck at the upload page. I know mechanize does not work with JavaScript but I was wondering if anyone knows a way that I could pass a file directory to the form to upload it, any help will be greatly appreciated.
<link rel="stylesheet" type="text/css" href="cssABI.css" />
<link rel="stylesheet" type="text/css" href="ABIDynamicMenus.css" />
<html>
<head>
<title>File Upload Provided by Aeries Browser Interface</title>
<script language="JavaScript" src="ABIjava.js"></script>
</head>
<body vlink="Blue">
<form name="frmValues" id="frmValues" method="post" action="FileUpload/Default.aspx?cache=5%2F19%2F2011+5%3A02%3A22+PM&LoadID=txtUploadedFileID&LoadNM=">
<input type="hidden" name="UserType" id="UserType" value="P" />
<input type="hidden" name="username" id="username" value="69297" />
<input type="hidden" name="number" id="number" value="200673" /
<input type="hidden" name="Check1" id="Check1" value="c91097e8cad20b230024a190d8867b3c65aceaaef6297c3788dd5b017bb89b2b" />
<input type="hidden" name="Check2" id="Check2" value="163f01c431991367a988152a35b947fa339359a7124c8fe9bc390d9c06f48a16" />
</form>
<script type="text/javascript">document.getElementById('frmValues').submit();</script>
</body>
</html>

Mechanize handles file uploads to forms like this:
form.add_file(open("NAME/LOCATION OF FILE"), "MIME TYPE", "NAME OF FILE")
br.form.add_file(open("file.txt"), "text/plain", "file.txt")

Related

Getting checked value after using back button

I have the following code on a web page:
<script>
jQuery(function(){
console.log($("[name='type']:checked").val());
})
</script>
<form>
A <input type="radio" name="type" value="A">
B <input type="radio" name="type" value="B"><br>
<input type="submit" name="submit" value="submit">
</form>
When I load the page, the output in the console is, naturally, 'undefined'. Let's say I select the 'A' option, click the submit button and then click the browser's back button. The 'A' option is still checked but the console output is also still 'undefined'. That doesn't seem right. Obviously I want the output to be 'A'. What am I doing wrong?
Are you sure that you are importing jQuery before running the script?
When recreating this issue, I got your wished result simply by importing jQuery first.
Working JS-fiddle: https://jsfiddle.net/961qgy4f/
Code:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<form>
<input type="radio" name="type" value="A">
<input type="radio" name="type" value="B"><br>
<input type="submit" name="submit" value="submit">
</form>
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
<script>
jQuery(function(){
console.log($("[name='type']:checked").val());
});
</script>
</body>
</html>

Refuse to execute Script when Including JS-Libraries in Thymeleaf Template

I want to use JQuery and JSEncrypt in my Thymeleaf Page.
From researching I've found that I can achieve this with including the .js files of the libs that are saved in my /static/js/ folder of the spring boot application.
I get the following error:
FolderTree:
My HTML looks like this:
<html ..>
..
..
<link href="../static/css/layout.css" th:href="#{css/layout.css}" rel="stylesheet" type="text/css"/>
<script type="text/javascript" th:src="#{js/jquery-3.5.1.min.js}"></script>
<script type="text/javascript" th:src="#{js/jsencrypt.min.js}"></script>
<script type="text/javascript">
function encryptPw() {
var encPw = $('#password').val();
console.log(encPw);
}
</script>
</head>
<body>
<form ...>
...
...
<p>
<label for="password" class="login-hidden-label">Passwort</label>
<input type="password" id="password" name="password" class="login-input-field" placeholder="Passwort" required>
</p>
<button class="login-accept-button" onclick="encryptPassword()" type="submit">Anmelden</button>
</body>
</html>
Solved this by allowing all Requests in the spring web security for
/js/**
in my antMatchers.
httpSecurity.antMatchers("/js/**").permitAll();
fixes it.

Facing difficulty to use pdfform.js in react app

I would like to use a pdfform.js library(package) within react app. I have tried by using the npm pdfform but no luck.
Any help is much appreciated.
https://github.com/phihag/pdfform.js
Here is a working demo, maybe it will help you.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>pddform.js demo</title>
<link rel="stylesheet" href="https://phihag.github.io/pdfform.js/docs/demo.css" />
</head>
<body>
<div class="error"></div>
<form class="url_form">
<div>Upload a PDF form file: <label><input type="file" name="file" /></label></div>
<label>or download one: <input type="text" size="40" value="Spielberichtsbogen_2BL.pdf" name="url" /><button role="submit">Download</button></label>
</form>
<form class="cur_file"></form>
<form class="lib_form">
PDF library:
<label><input type="radio" name="pdflib" value="minipdf" checked="checked" />minipdf</label>
<label><input type="radio" name="pdflib" value="pdf.js" />PDF.js</label>
</form>
<form class="fill_form"><button class="fill" disabled="disabled">Fill and download PDF</button></form>
<form class="list_form">
</form>
<div class="loading">Loading (this may take a while since PDF.js is gigantic)</div>
<!-- In a real-life scenario, you want to chose EITHER minipdf (smaller) -->
<script src="https://phihag.github.io/pdfform.js/minipdf.js"></script>
<!-- .. OR pdf.js (huge, but better compatibility).
pdf.worker.js is slightly modified to export the actual classes we care about -->
<script src="https://phihag.github.io/pdfform.js/customlibs/pdf.worker.js"></script>
<script src="https://phihag.github.io/pdfform.js/minipdf_js.js"></script>
<!-- pako and pdfform.js are required either way -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.3/pako.min.js" integrity="sha256-X7u/eQo6oIgWqc5jOmTjQn3loM8Lse0ock76Gkkn/Ro="
crossorigin="anonymous"></script>
<script src="https://phihag.github.io/pdfform.js/pdfform.js"></script>
<!-- FileSaver.js is just needed for the demo, although you'll probably use it in some form as well -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.0.0/FileSaver.min.js"></script>
<script src="https://phihag.github.io/pdfform.js/docs/demo.js"></script>
</body>
</html>

All input forms in MaterializeCSS in electron look smashed

Okay, so when I follow the directions here for getting started with Materialize CSS, my input form always turns out like this:
My current index.html file is this:
<!DOCTYPE html>
<html>
<head>
<title>IRS</title>
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="node_modules/materialize-css/css/ghpages-materialize.css">
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="node_modules/materialize-css/js/materialize.js"></script>
</head>
<body>
<div class="input-field">
<input placeholder="Placeholder" id="first_name" type="text" class="validate">
<label for="first_name">First Name</label>
</div>
</body>
</html>
My electron version is 1.6.6 and node is at 6.10.3
Add "active" class to the tag and try
<div class="input-field">
<input placeholder="Placeholder" id="first_name" type="text" class="validate">
<label for="first_name" class="active">First Name</label>
</div>
if you want only label animation, remove the placeholder for the <input> tag
Hope it works..
For anyone else with issues using materialize css with electron, here is how to get it to work the right way:
<script type="text/javascript" src="js/hammer.min.js"></script>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
The issue is materialize.min.js is requiring hammer.min.js so you need to add it to your project and call it before materilize.min.js

Why is my php script being downloaded instead of running?

I'm new to Javascript and PHP, and I'm currently going through the following tutorial.
http://www.html-form-guide.com/php-form/php-form-tutorial.html
Unfortunately, when I click submit, the myform.php file is being downloaded instead of being run. Is there something I'm missing?
<?php
if($_POST['formSubmit'] == "Submit")
{
$varMovie = $_POST['formMovie'];
$varName = $_POST['formName'];
}
?>
HTML code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example</title>
</head>
<body id="main">
<section id='ex'>
<form action="myform.php" method="post">
Which is your favorite movie?
<input type="text" name="formMovie" maxlength="50" value="<?=$varMovie;?>">
What is your name?
<input type="text" name="formName" maxlength="50" value="<?=$varName;?>">
<input type="submit" name="formSubmit" value="Submit">
</form>
</section>
test.php
?php
phpinfo();
?>
You need to run it in an HTTP server with PHP. I suggest WAMP for Windows sytems and MAMP for Mac OSX systems. For Linux search around for LAMP tutorials.
It could also be that your server is not configured to serve PHP files correctly.

Categories