This topic is locked
[SOLVED]

 need little help with validation

9/29/2013 2:08:16 PM
PHPRunner General questions
I
itmann author

Hi All,
i have following Tables

Table 1 - [Students] - which contains field: "age"
Table 2- [Seminars] - which contains 2 fields: "minimum_age" and "maximum_age"
in the Seminar View Page i created a new button "book Seminar"

i want this button to do a validation before a student can book a seminar:
if age > maximum_age ==> message "you are too old for this seminar"

if age < minimum_age ==> message "you are too young for this seminar"

else open page "book_seminar.php"
please help me with the right code to do this validation, and please let me know where to put the code (client before/server/client after)
thnaks

Sergey Kornilov admin 9/30/2013

Sure, this can be done

  1. Save the value of Age field from Students table in session variable $_SESSION["age"]. If Students is your login table you can use AfterSuccessfulLogin event for this purpose.
  2. Button's OnServer event

$result["message"]="";

$record = $button->getCurrentRecord();

if ($record["minimum_age"]<$_SESSION["age"] )

$result["message"] = "you are too young for this seminar";

if ($record["maximum_age"]>$_SESSION["age"] )

$result["message"] = "you are too old for this seminar";


3. Button's ClientAfter event

if (result["message"]<>"")

ctrl.setMessage(result["message"]);

else

location.href="book_seminar.php";
I
itmann author 9/30/2013

it works great. sergey you are the best !!