Jump to:

23372 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » TextField Readonly

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2874 Views
  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    TextField Readonly Link to this post

    I'm trying to set a textfield readonly.

    I see in the documentation that I can set a TextField to readonly, however how is this implemented?

    I have a custom form, but where do I put the readonly part for the field I want to make readonly?

    function Form() {
          return new Form($this, "Form", new FieldSet(

             // List your fields here
             new EmailField("Email", "Email address"),
             new PasswordField("Password", "Password"),
             new TextField("FirstName", "First name"),
             new TextField("LastName", "Last name"),
             new TextField("Phone", "Phone"),
             new TextField("Company", "Company/Hospital"),
             new TextField("Address1", "Address 1"),
             new TextField("Address2", "Address 2"),
             new TextField("City", "City"),
             new TextField("State", "State"),
             new TextField("Zip", "Zip"),
             new TextField("Country", "Country"),
             new TextField("IPAdress","IPAddress",$_SERVER['REMOTE_ADDR'])
             

          ), new FieldSet(

             // List the action buttons here
             new FormAction("SignupAction", "Register")

          ), new RequiredFields(

             // List the required fields here: "Email", "FirstName"
             "Email", "Password", "FirstName", "LastName", "Phone", "Company", "Address1", "City", "State", "Zip", "Country"

          ));
       }

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: TextField Readonly Link to this post

    Hmm, yes nothing in the Docs on the usage of this.

    I did find this inherited method however:

    setReadonly

    So maybe construct your field (I assume it's the IP field) seperately and try this before the new form declaration:

    function Form() {

    $IpField = new TextField("IPAdress","IPAddress",$_SERVER['REMOTE_ADDR']) ;
    $IpField->setReadonly(true);

    return new Form($this, "Form", new FieldSet(

    // List your fields here
    new EmailField("Email", "Email address"),
    new PasswordField("Password", "Password"),
    new TextField("FirstName", "First name"),
    new TextField("LastName", "Last name"),
    new TextField("Phone", "Phone"),
    new TextField("Company", "Company/Hospital"),
    new TextField("Address1", "Address 1"),
    new TextField("Address2", "Address 2"),
    new TextField("City", "City"),
    new TextField("State", "State"),
    new TextField("Zip", "Zip"),
    new TextField("Country", "Country"),
    $IpField

    .......

    Worth a stab

    Aaron

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: TextField Readonly Link to this post

  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    Re: TextField Readonly Link to this post

    Double-A-Ron,

    I seriously need to take a class on php5 functions and classes. I lack some serious knowledge that would go a long way in working with SS.

    Thanks for the inside.

    I certainly got the IPAddress to show up (easy) but would you expect the field to still be editable? I can erase the ip address.

    I'm testing now to see if the IPField still comes across in the email.

    Thanks again,

    Terry

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: TextField Readonly Link to this post

    Did you try making it a readOnlyField rather than use my code above?

  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    Re: TextField Readonly Link to this post

    Double-A-Ron,

    One million thank you's....That did it. I did the following:

    new ReadonlyField("IPAddress","IPAddress",$_SERVER['REMOTE_ADDR'])

    Worked perfectly...

    Thanks again,

    Terry

    2874 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.