0

I'm working on a form validation and I'm currently doing some debugging on my code. I'll insert the necessary code snippets below:

Form code:

echo '<h1> Seismic Recording </h1>
<div>
<form action="validate2.php" method="POST">';

echo "Latitude: <input type='text' name='latitude'>";
echo "Longitude: <input type='text' name='longitude'required>";
echo 'Wave Type: <select id="wave_type" name="wave_type" required>
        <option selected value="s">S</option>
        <option value="p">P</option>
        <option value="surface_wave">Surface Wave</option>
        </select>';
echo "Wave Value: <input type='text' name='wave_value' required>";
echo 'Upload CSV File: <input type="file" name="file">';
echo " <input type='submit' name='submit' value='submit'>";
echo "</form>
</div> ";

Validation code:

echo "w";

if (isset($_POST['submit'])) {
    echo "t";
    $latitude = $_POST['latitude'];
    if ($latitude  == NULL) {
        echo "Please insert a latitude . <br>";
        $error = $error + 1;
    }
}

echo "q";

The form validations that I've put within the if statement doesn't work. I tried debugging the code by inserting the 'echo "q"' and 'echo "w"' to see where the problem lies. Those statements work (they output the characters). But the 'echo "t"' within the if statement doesn't work. Why is that so?

Result of var_dump($_POST):

array(5) { ["latitude"]=> string(0) "" ["longitude"]=> string(1) "g" ["wave_type"]=> string(1) "s" ["wave_value"]=> string(1) "g" ["file"]=> string(0) "" }

My issue isn't so much in getting the latitude to validate but why doesn't the 'echo t' work?

Danielle
  • 33
  • 1
  • 6

5 Answers5

0

Why check for a 'submit' post variable when you're working with latitude?

if(isset($_POST['latitude']))
{
     echo "t";
     $latitude=$_POST['latitude'];
}
else
{
     echo "Please insert a latitude . <br>";
     $error = $error + 1;
}

Also there is no need for a name on the submit button

<input type="submit" value="Submit">
Stephan
  • 531
  • 3
  • 16
  • Because I'll be adding more validations within the if statement. My main question isn't about the validation of latitude but why doesn't 'echo t' work? – Danielle Oct 07 '16 at 15:34
  • Previous comment says all, in your post dump there is no submit post variable, that's why I wouldn't check for it. You have latitude, longitude, wave_type, wave_value, file. Just do your if isset statement on variables that actually get set. – Stephan Oct 07 '16 at 18:37
0
<!--form code start-->
<?php
if(isset($_REQUEST['req']))
{
    echo "Please enter any input";
}
?>
<form action="validate2.php" method="POST">
    Latitude: <input type='text' name='latitude'>
    <input type='submit' name='submit' value='submit'>
</form>

<!--validate2.php code start-->
<?php
if (isset($_POST['submit']))
{
    $latitude = $_POST['latitude'];
    if ($latitude  == NULL)
    {   
        header("Location:frm.php?req=error");
    }
    else
    {
        echo "Your input Text is: ".$latitude;      
    }
}
?>
Jay Prakash
  • 92
  • 1
  • 8
0

You just have your form rendering messed up, this works:

echo "<h1> Seismic Recording </h1>";
echo "<div>";
echo "<form action='' method='POST'>";

echo "Latitude: <input type='text' name='latitude'>";
echo "Longitude: <input type='text' name='longitude'd>";
echo 'Wave Type: <select id="wave_type" name="wave_type">';
echo '<option selected value="s">S</option>';
  echo '<option value="p">P</option>';
  echo '<option value="surface_wave">Surface Wave</option>';
echo "</select>";
echo "Wave Value: <input type='text' name='wave_value' d>";
echo 'Upload CSV File: <input type="file" name="file">';
echo "<input type='submit' name='submit' value='submit'>";
echo "</form>";
echo "</div>";

if(isset($_POST)){
  if(isset($_POST['submit'])){
   echo "Submit is alive!!";
  }
}

In order to avoid this kind of issues, remember that you can just write plain html, on this way:

<?php
  //Mi php code blablabla
?>
/* My html code */
<h1>Wonderful day, isn't it?<h1>

<?php
  //Another php tasks and etc
?>  
Hackerman
  • 12,139
  • 2
  • 34
  • 45
0
<!--Second Method--> 
<!--form code start-->
<form action="validate2.php" method="POST">
    Latitude: <input type='text' name='latitude'>
    <input type='submit' name='submit' value='submit'>
</form>

<!--validate2.php code start-->
<?php
if (isset($_POST['submit']))
{
    $latitude = $_POST['latitude'];
    if ($latitude  == NULL)
    {   
        echo '<script>alert("Please enter any input");
        window.location.href="frm.php";</script>';
    }
    else
    {
        echo "Your input Text is: ".$latitude;      
    }
}
?>
Jay Prakash
  • 92
  • 1
  • 8
0

Try this:-

$curl_connection = 
  curl_init('http://www.domainname.com/target_url.php');

link:-http://www.html-form-guide.com/php-form/php-form-submit.html

Razia sultana
  • 2,168
  • 3
  • 15
  • 20