0

I want a user to enter a string into a form (or use a js interface to build the string for them) which can then be logically evaluated server side.

For example: The event admin writes into a text area "((36&&37)||(37&&38))&&~42" which goes into a fee_option table. A registrant picked options 37 and 38. The registrant is then charge a certain fee because the expression evaluates true. I can see a basic option of replacing each number with the result of in_array($one_number,$options_selected_by_user) and then running that through some kind of regex security and then sticking that into an eval($str), but this is really just a dumb example.

My questions are then:

  1. Is there a conventional syntax for writing expressions to be evaluated apart from writing code to stick into an eval statement?
  2. Is there a PHP library, script, or even blog post that provides help when writing such a thing? Put another way - does everyone write user entered conditional statements for form builders and such from scratch everytime?
  3. Is there a javascript library specifically designed to build logical statements via a user interface, ie. grouping ors, ands, and nots, with a little math too probably.

1 Answer 1

1

Symfony Expression Language does the great job for your task. Give it a try.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.