[eluser]Unknown[/eluser]
Hi, i'm new to CI but know some PHP. Although this OO is new to me.
I'm building a web-page where users can register their participation for a competition.
In doing so, I have created a form, but before displaying the view containing the form I fetch some data about the competitor based on his/her registration number. This data is fetched from another site using some HTML-parsing through PHP (placed in a model) and stored in an array.
I then pass this data to the form view. If it was successfull in fetching the data, I want some of the fields to be populated with this data, if not, well, populated with explaining text, as "postal code" and such.
I have managed to complete this, but in the beginning of the form view, I have to do some testing for each variable, it looks like this:
Code:
if ( !isset($name) ) $name = "Name";
if ( !isset($street) ) $street = "Street";
if ( !isset($date) ) $date = "Date of first participation";
etc. etc...
As you can see, this becomes a bit tedious for a long list of variables. Is there a way to make this more easily? I would like to create a function that takes an array and does this for me, something like:
Code:
$variables = array (
'name' => "Name",
'street' => "Street",
'date' => "Date of first participation",
);
test_variables( $variables );
But I can't figure out how to create the array, nor the function.
I would appreciate any ponts to where I should look. I have tried these forums and read about form_validation and pistolPetes extended form_validation, but I'm unable to see how it could help me.
Thanks in advance.