-1

I am getting this...

Notice: Undefined index: cost, sku, costMethod

I think it is the validation part that is breaking this. I have tested sending these variables without the validation and they are received fine. I believe it is when everything is valid and the header gives it the destination is where it is losing the variables.

Here is my Form code:

<!DOCTYPE HTML>
<html>
<head>
<title>Shipping Overrides Client</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#additive").click(function(){
    $("#cost").attr("value","0.00");
  });
});
</script>
</head>
<body>

<?php
// define variables and set to empty values
$message = "SKU is required!";
$skuErr = "";
$sku = "";
$costErr ="";
$cost = "";


if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$valid = true;

if (empty($_POST["sku"]))
     {$skuErr = "SKU is required";
     $valid = false;}
   else
   {$sku = $_POST["sku"];}
   if (empty($_POST["cost"]))
     {$costErr = "Cost is required";
     $valid = false;
     }
   else
  {$cost = $_POST["cost"];}
  if(isset($_POST['costMethod'])){
  $costMethod = $_POST["costMethod"];
  }
 if($valid){
header('Location: SubmitFeedSample.php?sku=$sku&cost=$cost&costMethod=$costMethod');
exit();
}
}
?>

<h1>Shipping Override Client</h1>
<form method="post" action="index.php" >
SKU: <input type="text" name="sku" value="<?php echo $sku ?>">* <?php echo $skuErr;?><br>
STD Shipping Cost: $ <input type="text" name="cost" id="cost" value="<?php echo $cost ?>">* <?php echo $costErr;?><br>
<input type="radio" name="costMethod" id="exclusive" value="Exclusive" checked>Override 
<input type="radio" name="costMethod" id="additive" value="Additive" >Delete Existing Override <br>
<input type="submit" name= "submit" value="Submit">
</form>
</body>
</html>

Here is SubmitFeedSample.php:

<?php

 $shippingCost = $_POST["cost"];
 $sku = $_POST["sku"];
 $costMeth = $_POST["costMethod"];
echo $shippingCost . "<br>";
echo $sku . "<br>";
echo $costMeth . "<br>";
var_dump($_POST);
 ?>

How can I get the variables to send when valid?

0

2 Answers 2

1

You are making a GET request here -

header('Location: SubmitFeedSample.php?sku=$sku&cost=$cost&costMethod=$costMethod');

Try changing this -

<?php
 $shippingCost = $_GET["cost"];
 $sku = $_GET["sku"];
 $costMeth = $_GET["costMethod"];
 echo $shippingCost . "<br>";
 echo $sku . "<br>";
 echo $costMeth . "<br>";
 var_dump($_POST);
 ?>
Sign up to request clarification or add additional context in comments.

11 Comments

You could also consider just making SubmitFeedSample.php a part of index.php.
@ Tyler - Yes true. Still answering where he/she got stuck or getting error
More of a comment to the asker than you :)
@ Tyler - True again :D :D
Okay, changing the SubmitFeedSample.php page to _GET did the trick. I am getting the variables now. However, lets say I just want to use _POST and change the header to header('Location: SubmitFeedSample.php); without the variables in the url. That doesn't seem to work either. How could I get _POST to work?
|
0

You cannot redirect with header once headers have already been sent:

header('Location: SubmitFeedSample.php?sku=$sku&cost=$cost&costMethod=$costMethod');

That's why you are probably not getting the result there. Also that's not a proper way to fetch the post data. If you are passing arguments in URL like that you are using GET not POST.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.