I'm kind of new at php, so please forgive my code. I have a basic form submission which works great on my desktop browsers (haven't tried IE yet...), but doesn't work on my iPhone. It seems like it's reloading the page before it can do anything. The page just reloads and nothing is added to the database. Also, the PDF attachment doesn't show up either.
Any help would be greatly appreciated.
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input id="ctaemail" class="ctaemail" type="text" name="email">
<input type="submit" name="Download" value="Download" class="ctabutton" >
<?php
$con=mysqli_connect("localhost","usr","pass","db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if($_SERVER['REQUEST_METHOD'] == "POST"){
if (filter_var($_POST[email], FILTER_VALIDATE_EMAIL)){
$sql="INSERT INTO email_addresses (email) VALUES ('$_POST[email]')";
header('Content-type: application/pdf');
header('Content-disposition: attachment; filename=Carestream_Handout_Jan_2014.pdf');
readfile("Carestream_Handout_Jan_2014.pdf");
} else {
echo "That is not a valid email address. ";
}
if (mysqli_query($con,$sql)){
echo " Sucess! ";
} elseif (!mysqli_query($con,$sql)){
die('Error: ' . mysqli_error($con));
}
}
mysqli_close($con);
?>
</form>
use simply
<?php
$result = $_POST['postBody'];
echo $result;
?>
I'm not sure if anyone else will stumble across this problem again, though I was able to fix my php form issue in iphone by making sure all fields were NOT required. Wasn't really the way I wanted to fix it, but it seems to work now.