attock Posted August 25, 2009 Share Posted August 25, 2009 Hi guys, First post here! Here is what I am doing: - Store a Form template in the database - Fetch all the pre-fillable parameters (also stored in db) and assign them a variable. - Run eval() on the template to pre-fill. Every thing works fine, I can pre-fill. However, I also wana be able to dynamically select an option whithin a <select> tag (as shown in the code). It doesn't seem to be working. $form = ' <div class=\"fl w500 pl10\"> How long at current residence? <input type=\"text\" name=\"duration_current_residence\" class=\"fUline w100\" value=\"$duration_current_residence\" /> </div> <br class=\"clearB\" /> <div class=\"fl w500 pl10\"> If less than 2 year, list prior address? <br class=\"clearB\" /> <div class=\"fl\" style=\"margin-left:50px;\"> <input type=\"text\" name=\"prior_address1\" class=\"fUline w400\" value=\"$prior_address1\" /><br/> <input type=\"text\" name=\"prior_address2\" class=\"fUline w400\" value=\"$prior_address2\"/><br/> </div> </div> <br class=\"clearB\" /> <div class=\"fl w500 pl10\"> Do you own your home? <select name name=\"own_home\" class=\"w50\" /> <option value=\"yes\" \'.( $val == 1 ? \"selected\" : \" \" ).\' > Yes </option> <option value=\"no\" \'.( $val == 2 ? \"selected\" : \" \" ).\' > No </option> </select> </div>'; // pre-fillabel variables $val = 2; // dynamically select own_home $prior_address1 = 'ssssssssss'; // address 1 @eval("\$output = \"$form\" ; "); echo $output; So I guess my question would be how can I use if statements within eval(). Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 25, 2009 Share Posted August 25, 2009 you can - eval will execute the string argument as code. but why? eval is very expensive, as is database storage. Have you looked at storing your form in a flat file? or even better - an xml format that can be parsed (this gives enourmous power and if done right you can build forms very quickly and easily AND apply the backend functionality all in one go. takes a bit of work mind you Quote Link to comment Share on other sites More sharing options...
attock Posted August 25, 2009 Author Share Posted August 25, 2009 ToonMariner: Actually its a good idea plus a better solution, will give that a try. However eval() doesnt seem to be working in this senario, else why would I have posted this question Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.