• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Disabling changes to a form field

I have a simple form setup and I'm using PHP to read the form and send the data to a text file.  I only want the user to able to modify a few of the fields.  The rest I've set to have values.  I want to set my page up so that the user can not modify the fields that already have values.  Here's what I tried:

<input type="text" name="Field1" size="30" maxlength="2" value="H0" id="Field1" disabled />

The disabled prevents the user from entering anything into the field and the field still shows my value of H0.  However, PHP doesn't see any text in the field and therefore does not store anything to my text file.

So is there a simple CSS/JS script I could use to stop users from entering characters into specific fields?
0
TacomaVA
Asked:
TacomaVA
  • 2
  • 2
2 Solutions
 
LordZardeckCommented:
Can you not just set the values in the disabled text boxes as default values in your php script?
Like this (crude, but trying to make a point):

<?php

   $_POST["Field1"] = "H0";

?>
0
 
LordZardeckCommented:
If not, you can have your textbox watch for any keyboard strokes, and return null each time. Not sure exactly how that would be coded, but it's not easy. I've done something similar, but a LONG time ago.
0
 
leakim971PluritechnicianCommented:
Hello TacomaVA,

Use : readonly="readonly"
Not : disabled

Regards


<input name="Field1" type="text" id="Field1" value="H0" size="30" maxlength="2" readonly="readonly" />

Open in new window

0
 
TacomaVAAuthor Commented:
Thank you, both of you!  Both solutions worked!
0
 
leakim971PluritechnicianCommented:
Thanks for the points! Happy new year!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now