I'm creating a set of scripts for creating forms without much html coding. The idea is this:
- I already coded a php class for creating html widgets in a php script. It's something as
$mytextarea=new textarea("textarea_name", "text_area_value");
$mytextarea->create();
The class is more complex, it can create any widget, and apply any html attribute, using methods, like $mytextarea->setTabIndex(3); $mytextarea->setDisabled();, and too, set a value from a database, like $mytextarea->setSQL("SELECT value FROM table WHERE idValue=2");
- Now, I just found the 'eval' function, so, I got an idea, write a script, that write a script. So, if I have a resource file like:
[last_name]
type=text
value="Jonh Doe"
size=20
maxlen=40
...
One script could read this resource file, and, for every item, create the corresponding widget with the php class on 1. , the way to do this is writing the code in a variable, and then pass it to eval function.
- I thought that use xml for the resources file it's the best choice, so, using xml_parse_into_struct, I read the xml file (resource file), I got the structure on memory. The idea is, coding html; in the parts where a html widget, a graphic, or any dynamic part is needed, put a label, like ####input_name####. So, the designer only writes html, and uses labels to be processed for the programmer. The programmer, then, writes a simple script, telling what labels will be replaced, and what is the result of the replace. To make easier, I call to a 'super function', named 'evalua' (spanish for 'eval'), that searches for the label, gets its type, and others attributes, and then create an script, in memory, and finally execute it with php eval function.
There are 3 files for every page, so, if the page is 'payment', there are 'payment.htm' (the template, with ####labels#### inside), 'payment.xml' with resources defined, 'payment.php', that process html file, mixes with xml, and create a memory script, then show in browser.
Ok, the ideas i need is that, in xml, I define that some widget has to run a sql to get its value, for example:
<age_field type="text" query="SELECT age FROM users WHERE idUser=$x" accesskey="N" alt="Please, your age" tabindex="1"/>
Note that in the xml file I'm using a variable, $x. This file is read, and the value 'query' should be evaluated to get $x value, and transform in a SQL valid sentence. So, I use eval here. The problem is that generally, everybody uses $GET[''] or $POST variables to identify the element, comming from a previous page so, the code above changes to
<age_field type="text" query="SELECT age FROM users WHERE idUser=$_GET['idUser']" accesskey="N" alt="Please, your age" tabindex="1"/>
Eval fails. It can't get the value of the sql sentence because $GET is an array, and the sintax need to be ['var'] like, so eval fails. so, may be I need to define the sql source in a different way that now, may be putting a sql sentence in a xml file is not recommendable, may be I should extract $GET elements to variables to avoid this problem, may be I need to ... I don' know what to do.
If payment.php receives a value to query a database, xml have the incomplete sql, and is needed to write code in memory to be executed with eval, what do you think I should do?