mardi 2 mai 2017

In a Form Model Binding form, how do I access the variable without using a helper?

In the Form Model Binding section of the documentation (http://ift.tt/2p4kHvS) it says how the model's value is conveniently available with the value being set in the priority order of:

  • Session Flash Data (Old Input)
  • Explicitly Passed Value
  • Model Attribute Data

This is super useful because if a user has changed multiple fields, but 1 of which fails validation, you don't want all the other fields being reset to original value when they get thrown back to the page with a helpful Message Bag of errors.

It's all very well using the Form::label, Form::text and Form::select helpers to leverage this lovely feature but what if you just want to access that convenient variable directly to do something a bit left-field?

Here's what I have tried...



    
    

          <-- No
        <-- Nope
          <-- Still no
      <-- Absolutely not



The documentation hints at the ability to get the thing I want here: http://ift.tt/2oTa6Is where it says it's "easy" to define your own custom Form class helpers called "macros" but it doesn't actually tell you where you would write this or where in the code you can look if you want to poke around and learn more about the FormBuilder class.

It really feels like Taylor was distracted by some builders outside the window when he wrote this page of the documentation because it just seems lacking compared to the usual depth of the other pages.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire