-1

So I am using this form to submit to PHP file. PHP file has a redirect header that WORKS when I call the php file directly in browser, but when it is accessed via the action attribute in the form, it does nothing. There was a time I could make it redirect without the refresh: 2, but then the issue arose that it was only including the redirected file within the php document itself, so my javascript and submit functions would fail... Weird? Please advise! What's going on?

HTML

<form name="ats_routing" id="ats_routing" method="post" action="php/upload.php" enctype="multipart/form-data">

    <!-- Some html generated by codiqa -->

    <a onclick="submitForm();" data-transition="flip" data-theme="" data-icon="check">
        Submit
    </a>
</form>

Javascript part

/****CREATE JQUERY SUBMIT FUNCTION FOR IFRAME VALIDATION CHECK FOR Codiqa****/
function submitForm() {
    if ($("#ats_routing").valid()) {
       //alert("Thank You. Your Routing Form Has Been Submitted.");
       $('#ats_routing').submit();
    }
}

PHP that form redirects to (upload.php)

<?php
header("Refresh: 2; URL=/ats-routing/"); /* Redirect browser */

//Parse and store the db ini file, this will return an associative array
db_config_ats_ibutton();
db_connect();

$total_weight       = $_POST['total_weight'];
$uf             = $_POST['number_uf'];


$query="INSERT INTO datbasae (
    lbs_uf,
    total_weight,
    district)

    VALUES(
    '$uf',
    '$total_weight',
    '$district')";

query_db($query);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
  <title>ATS Routing</title>
  <link rel="stylesheet" href="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.css">
<link rel="stylesheet" href="http://dev.rs.idmyasset.com/ats-routing/css/theme.css">
<!-- Extra Codiqa features -->
<link rel="stylesheet" href="https://codiqa.com/view/bb40208d/css">
<!-- jQuery and jQuery Mobile -->
<script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
<script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js">    </script>
<meta http-equiv="refresh" content="2; url=http://dev.rs.idmyasset.com/ats-routing/">
</head>

<body>
<!-- Home -->
<div data-role="page" id="page1">
  <div id="header" data-theme="" data-role="header">
      <h3 id="header">
          ATS Routing Data
      </h3>
  </div>
  <div data-role="content">
    <h1 align="center">Thank You</h1>
    <h1 align="center">Your Form Has Been Submitted!</h1>
  </div>
</div>
</body>
</html>
Nek
  • 2,715
  • 1
  • 20
  • 34
jflay
  • 514
  • 9
  • 32
  • If you are uploading a file you will need to add the following attribute to your `
    ` element: `enctype="multipart/form-data"`; not sure if that could be causing your woes, however. If you're just accepting text and calling it an upload, ignore this.
    – Dereleased May 21 '13 at 21:08
  • If you don't want the 2 second refresh....why don't you just redirect like a normal person? :) – cHao May 21 '13 at 21:13
  • I want the THank you Message, so the refresh allows the message to display for two seconds, and then I want to redirect back to form... and like I said in my post, if I redirect like normal, the header() just loads the page WIITHIN the upload.php file, so I lose all my javascript and functions, therefore disabling my form's functionality since it isn't redirecting to the main html page itself. – jflay May 21 '13 at 21:18

2 Answers2

2

First and most important: There is no HTTP header named "Refresh". Browsers might react to it, but it is not defined.

So why do you use it? You are emitting HTML, you do not need the Refresh HTTP Header. Remove it.

Which brings me to the Refresh meta tag. Does this one work, or is it supposed to work?

Currently you are creating a confusing situation for the browser: You present two different values for the URL to got to after 2 seconds. One is from the HTTP header, which isn't official? Should this take precedence over the meta tag like any other HTTP header, or is this an exception because non-standard HTTP headers and standard meta tags are the other way round?

And now for something completely different: Your code is attackable with SQL injections. Always escape all variable content that goes into a SQL statement!

Sven
  • 69,403
  • 10
  • 107
  • 109
  • I have tried using both, one without the other, and same issue with the meta refresh header in the transition html. It works when I call the upload.php file directly, but not when it is called via the form action. – jflay May 21 '13 at 21:49
  • yes. thanks for the word of warning about SQL. I agree!! http://stackoverflow.com/questions/16329662/demonstrating-sql-injection-attacks-to-my-boss – jflay May 21 '13 at 21:54
1

Most part of the code you show is useless. As you suggest your problem is "from php" (in facts, probably not). You have to give the PHP code, not the html or JS (ok, why not the JS, but more than just that).

You're saying sending file from your form, you need a form tag who look like that:

<form action="something" method="post" enctype="multipart/form-data">

The enctype part is missing. But... I see no file input in your form, you removed all the content...

Nek
  • 2,715
  • 1
  • 20
  • 34
  • I am using Codiqa so it uses a link submit button and so I call the submit function via JS... I have used the enctype and it doesn't work either, the header redirect in PHP that is. I figured all other content is irrelevant to this post but the form HTML and the PHP, but wanted to be thorough. – jflay May 21 '13 at 21:15