-1

I want to check the condition based on input item. This item is in model window . i wrote the condition in model window.

<?php 
if( ($_POST['title'] == 3) )
{ 
   ?>
      <input type="file" name="file" accept="image/gif,image/jpeg,image/png,image/jpg" />
   <?php 
} else {
   ?>
         <input type="file" name="file" accept="application/pdf" /> 
   <?php 
} 
?>

It shows the error below:

Message: Undefined index: title

Ronnie Oosting
  • 1,252
  • 2
  • 14
  • 35
kingofking
  • 27
  • 6

2 Answers2

0

You can check condition as below :

<?php 

if(isset($_POST['title']) && ($_POST['title'] == 3))
{ 
   ?>
      <input type="file" name="file" accept="image/gif,image/jpeg,image/png,image/jpg" />
   <?php 
} else {
   ?>
         <input type="file" name="file" accept="application/pdf" /> 
   <?php 
} 

?>
Vivek Sangani
  • 401
  • 2
  • 8
0

I would use this:

<?php
$title = (is_int($_POST['title']) && $_POST['title'] >= 1) ? $_POST['title'] : 0; 
// This allows you to check whether $_POST['title'] is an integer, if it is 1 or higher. If that is the case, $title will be $_POST['title'], else it will become 0 (zero).
// It will also do a check on given $_POST data to prevent false input.

if ($title == 3): ?>
    <input type="file" name="file" accept="image/gif,image/jpeg,image/png,image/jpg" />
<?php else: ?>
    <input type="file" name="file" accept="application/pdf" />
<?php endif; ?>

Documentation:

Ronnie Oosting
  • 1,252
  • 2
  • 14
  • 35