CheeKeeDee
CheeKeeDee

Reputation: 15

How to get the value in the pre-set text field?

Good Day People,

I am a newbie PHP programmer, I have a problem on how I can get the value in one of my text field which is already preseted. when I submit the form, I receive this error:

 Notice: Undefined index: requestor in C:\xampp\htdocs\SetUpFileForm\output.php on line 16

Notice: Undefined index: dateSubmitted in C:\xampp\htdocs\SetUpFileForm\output.php on line 18

here's my code My goal here is to auto populate the requestor field with the one who is currently logged in:

<?php $user = $firstname . ' ' . $lastname; ?>
    Requestor:<input type="text" name="requestor" value="<?php" echo $user; "?>" disabled="yes">

Thanks a Lot,

CheekeeDee

Upvotes: 0

Views: 82

Answers (3)

Arun G
Arun G

Reputation: 1688

The problem is the way you used php echo inside your input tag

try this

<?php $user = $firstname . ' ' . $lastname; ?>  
Requestor:<input type="text" name="requestor" value="<?php echo $user; ?>" disabled/>

Upvotes: 0

Dinesh Rawat
Dinesh Rawat

Reputation: 1019

YOU WILL NOT ABLE TO GET THE VALUE OF ANY DISABLED FIELD OF HTML IN PHP.

Undefined warning message comes when you are using the index that is not been defined or that doesn't exists in the $_REQUEST array.

What you can do is print_r you _REQUEST array like this:-

echo "<pre>";
print_r($_REQUEST);

check if requestor or dateSubmitted is the index for this array.

AND you should check first if an array elements value is set and not empty like this:-

$requester = '';
if(isset($_REQUEST['requestor']) && !empty($_REQUEST['requestor'])) { // By doing this there will be any warning like undefined index, and its a good practice too
  $requester =  $_REQUEST['requestor'];
}

Hope it is helpful!

Upvotes: 1

user3778553
user3778553

Reputation:

Don't use disabled attribute, use readonly attribute:

<?php $user = $firstname . ' ' . $lastname; ?>
Requestor:<input type="text" name="requestor" value="<?php echo $user; ?>" readonly />

Upvotes: 1

Related Questions