Did you add the ID to your form submit code? I may not have stressed
that, and it’s important. In your Form Setup dialog, make sure that
the Action is set to this:
yourformpage.php?id=<?=$id?>
That, along with commenting back out the direct value assignments you
made below, should be it. Oh, and if you’re using my code explicitly,
then make sure that your submit button is named exactly ‘save’.
Otherwise, change the line that reads
if(isset($_POST['save']))
to match the Name property of your submit button (set in the third tab
from the left in the Inspector). If these don’t match, then your form
will never be handled at all, it will just sit there like a pudding,
always loading the defaults.
The way this form process works is as follows:
-
The page loads initially without an ID set for the record. This
causes the handler to conjure up a blank object with
MyActiveRecord::Create(‘YourModel’).
-
extract(get_object_vars($yourModel)) loops through all of the
properties of that blank object and creates global variables for each
property.
-
Your Freeway HTML/PHP loads, using those global variables to fill
in the blanks. (They’re all set to whatever the default value is for
each column in the database.)
So that gets you to the point where the user sees the form for the
first time. Now let’s say the user has filled everything in.
-
The form is submitted to itself. The form handler receives the ID
in the URL (the GET), and the rest of the form body in the POST.
Because this is the first submit, the ID is set to 0.
-
The form handler conjures up another blank object. (The first one
was never saved, so you’re not adding records without values to your
database when you load the empty page for the first fill-in – you’re
just using the “idea” of the object as a template.) This time, it uses
$yourModel->populate($_POST); to fill in all of the values.
-
When the handler calls save(), it invokes the save method in your
model, so if you created some required variables and the user did not
fill those in, you would find that save would fail, setting an error
on the model which you could extract using get_errors(). If there are
no errors, the handler redirects you back to the form page, but this
time sets the $id variable to the actual ID of the just-created
record. When the id is real, then the form loads with whatever the
database knows about that real record.
If the form submission fails, and there are one or more errors, then
the form handler “falls through” to the form itself. (Well, it would
if we took the die() statement out of the sample code and replaced it
with something that could make a nice human-readable error message.)
In this case, the record is not saved, but all of the values that the
user just submitted are still there in the object, waiting to be
extracted into the global space. This gives the user back everything
that she entered, so that the errors can be corrected without the use
of the Back button or having to re-enter anything that was entered
correctly.
Walter
On Nov 16, 2010, at 1:39 AM, Soren F wrote:
Hi Walter,
Now the page loads without errors, and if I do the following then it
reads the DB, and the checkboxes are marked (I have put in a few
values manually by using the mySql admin tool):
$id = “1”;
//$id = (isset($_GET[‘id’])) ? (int) $_GET[‘id’] : 0;
You mentioned it is critical to have global values, so I tried to
put in the following:
$foo = “0”;
$bar = “0”;
$baz = “0”;
These values match the names of the Checkbox´s. But I can see in the
mySql Admin tool that the changes I do on the webpage are not stored
in the DB, when I press “send”.
Do you have an idea what the reason could be?
Thanks again! 
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options