The validation we just introduced stops us from inserting a record into the database.
If we don't enter valid values for the title and content we'll get to validating the publication date
later on.
The farm is redisplay aid with error messages.
But if we happen to have supplied a value in one of the fields but one of the others is invalid and
we submit the farm the data that we originally typed in is lost.
It will be much more user friendly if the redisplay farm maintains the data that we originally typed
in.
So let's try setting the value attribute of the title input to the value from the post array like that.
As you might have guessed when we first load the farm the post to raise empty so are trying to access
an array element that doesn't exist gives us an error the error appears inside the title input.
That's what we set the value of the control to.
We could put an F statement in here to check if the arraignment exists but we'd have to repeat that
for every single control and our 8 p.m. hour would start to get messy with lots of P HP embedded in
it.
Plus we are already checking to see if the farm has been submitted up here so we can take advantage
of that.
So let's replace this post to rate element.
With a variable called Title.
Then if the form is submitted.
That's a sign the value from the farm to this variable.
If the form isn't submitted we still need this variable to exist.
Otherwise we're back to the same error we're trying to fix.
We could add an else block to this if but seeing as we are ready initializing a variable here that we
later use in the farm.
This is a good place to do it.
So let's initialize the title variable here like that.
Now when we first load the farm there's no error and if we supply a value for the title but not the
content.
So the farm is invalid when we submit the farm.
The farm is redisplay displayed with the validation error and the value we typed into the title field
has been maintained.
Let's do the same for the other two controls with initialize some variables at the top then set the
values to the data coming from the farm when it's submitted and then in the next term I'll use these
variables to redisplay the data for the other two farm controls.
Like that.
So now if we leave the title blank would enter values for the other two fields.
When we submit the farm and it's re displayed the values of the other two fields are maintained.
There's one more thing we can do to improve our code slightly.
When the farm is submitted we're assigning the values coming from the farm in the post super global
to these variables.
However we're still using this post to Ray when we're validating the data.
And also when we insert it into the esky Well our code will be easier to maintain.
If we reduce the amount of times we use a global variable like this.
So let's change the validation to use our new variables instead.
And also where we're binding these values to our Prepared Eskew our statement like that.
So now our farm values are maintained when we submit an invalid form making it much easier to correct
any validation errors and resubmit the form.
And if all the data are valid a new rijkaard is inserted as before.