Javascript form not posting to IE 9 - javascript

I've got a very simple Javascript form that posts to a PHP page. This page is launching from a CRM system and the page itself can only be an HTML page, so I can't use PHP for the form. The form posts the user id (which is generated by the CRM system) over to a PHP page and then does a load of stuff based on the UserID.
The problem, however, is that some users now have IE9 and it doesn't seem to work with that! IE 8 is absolutely fine, but IE9 just doesn't seem to post the userid.
The form within the CRM system is as follows:
<form action="http://intranet-srv02/reports/contact.php" method="post" onsubmit="target_popup(this)">
<input name="userid" type="hidden" value="[userid]" />
<input type="submit" value="Reports" />
</form>
<script language="JavaScript1.2">
function target_popup(form) {
window.open('', 'formpopup', 'width=1100,height=750,resizeable,scrollbars');
form.target = 'formpopup';
}
</script>
And when, on the contact.php page put
<?php
$userid = $_POST['userid'];
echo $userid;
?>
Nothing echos on IE9 (but on IE8 and others it does)
Any help much appreciated!
EDIT: I've updated the deprecated language attribute, but still having the same issue. The form now reads:
<form action="http://intranet-srv02/reports/contact.php" method="post" onsubmit="target_popup(this)">
<input name="userid" type="hidden" value="[userid]" />
<input type="submit" value="Reports" />
</form>
<script type="text/javascript">
function target_popup(form) {
window.open('', 'formpopup', 'width=1100,height=750,resizeable,scrollbars');
form.target = 'formpopup';
}
</script>
Any other ideas?!

So it turns out that there is a (currently unknown exactly what) problem with IE9 and user profiles.
Possibly the problem is when users were on XP and then they started working on a Windows 7 box. Ultimately we haven't completely narrowed it down yet, but re-creating the user's profile seems to fix the issue!
The joys of Windows...

Related

Google Apps Script: submit form + keep window content + make browser make an offer to save name/password

I´m trying to submit a HTML form while keeping content of displayed page on the screen and triggering browser to make an offer to save username and password.
<div id="signInForm" class="init">
<form>
<input id="username" type="text" placeholder="Username">
<br><br>
<input id="password" type="password" placeholder="Password">
<br><br>
<button type="submit">Sign in</button>
</form>
</div>
I´ve found out, that keeping content can be done various ways:
preventDefault(), onsubmit="return false", action="javascript:".
I successfully made work each of them. But each of them prevents browser (Chrome and Edge) from doing an offer of saving username and password. As long as I´ve learnt, an HTML form has a default behavior on submit which is navigating to the submission link. My theory is that the "navigating event" itself is what triggers an offer to save username and password. If I´m right, the only way to reach my goal is probably based on letting submission happen default way, while making browser keep the content somehow.
Bur all I ever get after hitting <button type="submit">Sign in</button> is a blank page.
Is it even possible to overcome this simply in Apps Script? Or am I missing something basic?
I tried to programmatically reload my page, but wasn´t able to do so. I don´t know how to work with reload().
I´ve tried this:
<!DOCTYPE html>
<html>
<body>
<div id="x">I´m ORIGINAL page</div>
<button onclick="document.getElementById('x').innerHTML= 'I´m EDITED page';">edit page</button>
<br>
<button onclick="myFunction()">Reload page</button>
</body>
<script>
function myFunction() {
window.location.reload(true);
}
</script>
</html>
The snippet above works for me in Stackoverflow snippet editor, but it doesn´t work in my published GAS web app.
EDIT Probably close to solution for my problem is answer in this post: Redirecting from doPost() in Google Web App, HTML form with App script where the author suggests this:
<form method="post" action="<?!= ScriptApp.getService().getUrl() ?>">
<input type="submit" value="submit">
</form>
But it does nothing for me when copied and pasted and I don´t know how to implement it any other way. It looks general...
I was having the same issue when trying to avoid the page to reload to a blank page. The solution that worked for me was a piece of code that is on Google Apps Script Documentation (I leave the link here)
I hope this solution can help you to solve the blank reloading issue.
<script>
// Prevent forms from submitting.
function preventFormSubmit() {
var forms = document.querySelectorAll('form');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
window.addEventListener('load', preventFormSubmit);
</script>

IE8/9 - Submitting form with image file async - no formData support

I'm trying to build a form to asynchronously upload images to my site. It works perfectly on newer browsers and then the AJAX updates my list of images without refreshing the entire page.
The problem I'm having is it doesn't work on IE8 & IE9 (and probably others) because those browsers don't support "FormData". I need an alternative where a user uploads an image (with additional hidden form input fields), the list of images should update after the upload is complete - WITHOUT having the entire page refresh.
Here is basically what I have so far:
<div class="imagelist">
... list of images here should be updated by ajax after each upload...
</div>
<form name="uploadform" id="uploadform" method="post" action="/edit-images/uploadimage.php" enctype="multipart/form-data">
<input type="hidden" name="itemimagesid" value="<?php echo $itemid; ?>" />
<input type="hidden" name="itemtype" value="new" />
<input type="file" name="imagefile" id="imagefile" onchange="uploadFile()">
</form>
<script type="text/javascript">
function uploadFile() {
if (!window.FormData || window.FormData === undefined) { // old crappy browsers that can't use ajax/file submit.
$('#uploadform').append("<input type='hidden' name='oldbrowser' value='1'>");
...
[ need a solution here ]
...
return;
}
}
</script>
I need something that works in 2016. I have bootstrap 3.3.2 which uses the jQuery version 1.11.2. I've searched stackoverflow and none of the solutions work. I've tried "jQuery Form Plugin", that does absolutely nothing, doesn't even initialize - probably because my jQuery version is too new for that script. Hopefully there is a better solution for today.
Nevermind, I was able to figure out the iframe hack.

Submitting a form and closing the window - the correct way to do it?

I am trying to submit a simple form that is in a pop-up dialog and then close the dialog.
The best article I've seen is Submit a form in a popup, and then close the popup but it seems to work intermittently for me. The page launched by the form is a PHP page that modifies a record in the database. I thought that once the request is sent the PHP page will execute, even if the launching window is closed. Apparently not though. Sometimes the table is updated, sometimes it isn't. It seems like if the SQL operation isn't fast enough the page will be closed and the process is killed.
Here's the code:
<form id="xlationform" action="updatexlation.php" method="post" onsubmit="return closeForm(this);">
Source: <br>
<textarea disabled name="sterm" rows=10 cols=50><?php echo $source ?></textarea><br><br>
Translation: <br>
<textarea name="xlt" rows=10 cols=50><?php echo $xlation ?></textarea><br><br>
<input type="hidden" name="id" value="<?php echo $termid ?>">
<input type="submit" value="Update">
</form>
<script>
function closeForm(f) {
f.submit();
window.close();
}
</script>
What's the best way of working this out? I want the window to be closed but the DB operation needs to complete first and I don't want to query the DB again if possible. Thanks for your help.
Do it in updatexlation.php like :
$e = mysqli_query(...) if ($e) { echo "<script>window.close();</script>"; }
But as mentioned above, avoid using popups.
The response page should simply have window.close in the onload event.

Can I force a page in history to be removed?

Re editing... this question has NOT been answered before!
I had understood that changing the contents of a current page with window.location replaced the cached version of the original page ( from the "last" history), so that you really couldn't go back with the browser BACK button. I had even seen this posted as a solution to preventing a malicious visitor from using the BACK button to to re-submit a mail form many times. But it is NOT workable because in the case of a mail form, the BACK button will just take the user back to the pre-POST version of the page.
So, I can use javascript to reset the form, disable the SUBMIT button, change to another page after success, or do whatever I want to the page. But its all for nothing if a simple click of the BACK button followed by SUBMIT causes the form to post again with just 2 clicks.
I know there are a lot of solutions to preventing malicious form resubmissions I can try, but I've had trouble getting them to work, and so I'd just like to know if removing the last history is a dead end. If there is a way, and it is pretty cross browser friendly, then I can just make it part of my scripted actions once my form is successfully processed, and my "thank you" page displays. Basically I'd want my "thank you" page's 'onload' event to either erase the last history, or in a browser compatible way disable the BACK button!
For what its worth, I've included code from simple test I've been working with. You can put some junk in the fields and hit submit. The vars are cleared in the PHP, the form fields are force cleared in javascript, and a new 'location' is invoked. Unfortunately, hitting BACK button will take you back to the "pre-posted" form, with all the strings you added still intact.
<!DOCTYPE HTML>
<html>
<head>
<title> Form Behavior Test</title>
</head>
<!--
<?php
$name = $email = $comments = "";
$formDone = false;
if ($_SERVER["REQUEST_METHOD"] == "POST" )
{
$formDone = true;
$name = $email = $comments = "";
}
?>
-->
<body >
<table border="1"><tr><td style ="text-align:right;" width=100%>
<form name="contactform" id="contactform" method="post" enctype="multipart/form-data" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name" id="name" value="<?php echo $name;?>"><br>
Email: <input type="text" name="email" id="email"value="<?php echo $email;?>"><br>
<br>
<div align="center"> ---- <span class="error">*</span> Message ---- <br>
<textarea name="comments" id="comments" wrap="physical" cols="40" rows="10" ><?php echo $comments;?></textarea>
</div>
<input name="submit" id="submit" type="submit" value="Submit" >
</form>
</td></tr></table>
<script language="JavaScript">
if (<? echo ($formDone == true) ? 'true' : 'false'; ?>)
{
document.getElementById("name").value = "";
document.getElementById("email").value = "";
document.getElementById("comments").value = "";
document.getElementById("submit").value="Disabled";
document.getElementById("submit").disabled=true;
// substitute with a thank you page
window.location = "http://google.com";
}
</script>
</body>
</html>
After searching pretty exhaustively, I don't believe there is any way to remove a page from history, except on the very latest browsers that support newer HTML-5 history methods. I'm still open to solutions but at this point I think the easiest thing will be for me to set a cookie anytime a successful email is processed by my PHP code. Then, I can also make the PHP or a javascript snippet look for the cookie and if found, I can take all kinds of actions... wipe out all filled in fields (as they would be if the BACK button is pressed), block the email, politely inform the user that he/she must wait (until my cookie expires) to send another email though the form, etc.
I didn't want to do this originally because the BACK button doesn't actually re-load the page, it just displays it. If there were a universal browser compatible way to make pages reached by back buttons actually re-load, this would never have been a problem to begin with. So even with a cookie, my defensive actions couldn't activate until the SUBMIT button is pushed. I guess I can live with that. Also, even today, some people are paranoid about cookies and turn them off. But if I want to be adamant about it, I can just detect when I can't set a cookie, and inform the user that cookies are required to use my email form. If that's too big a deal, oh well!
Thanks to those that contributed. The fact is, the LACK of answers is really a very useful answer sometimes. When I post on any stackoverflow forum and don't get any answers pretty quickly, its a good red-flag that things are going to get convoluted really fast if I don't consider an alternate approach! :-)

Opera Input Doesn't POST

I have created a script which posts data to a page automatically. It can be found below:
echo '
<html>
<body onLoad="javascript: document.process.submit();">
<form method="post" action="pagehere.php" name="process">
';
foreach($post_data as $k => $v) {
echo "<input type='hidden' name='$k' value='$v' />";
}
echo '
<input type="submit">
</form>
</body>
</html>
';
It works as intended in all other browsers apart from Opera (testing on version 11.50). The <form action> attribute works and the user is redirected to the new page. However, the hidden input fields are not sent to the new page.
I have tried removing the JS and replacing it with a standard submit button, with no luck. I have also tried using standard <input type="text"> tags just to test, and again, have had no luck. Oh, and no luck submitting with jQuery either, although that again was fine with IE/FF.
Am I missing something stupid, or is this a very strange problem?
Thanks.
After hours of searching the internet, it turned out I was looking at the wrong thing completely. The proxy settings in Opera were not configured correctly for my development environment...
Thanks to everybody who took the trouble to read/answer.

Categories

Resources