Jump to content

Dynamic decissions \ if statements within EVAL()


attock

Recommended Posts

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().

 

 

 

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.