This topic is locked

Conditional Required Fields

11/28/2007 1:24:47 AM
PHPRunner General questions
M
MikeB941 author

Hello:
PHPRunner 4.1 - Build 320
Is there a way to CONDITIONALLY make fields either required/validated or not?
As an example, we would like our administrators to be able to go in and edit a users record and be EXEMPT from the required fields and validations performed for a normal user. Specifically, many times we set up a skeleton record that has to be completed by the end user using the ADD page... the record is then turned over to the user to EDIT with guidance from all the required fields and validation that's in place - sometimes and administrator makes an error when setting up the initial skeleton record and has to go back in to make some minor corrections before turning it over to the user, but on the EDIT page they get trapped into required fields and validations that were intended for the normal user when completing the records.
I would prefer NOT to set up a separate view and a duplicate EDIT page (hoping for some fancy EVENT CODE to disable required fields and validation conditionally (if the user is an administrator).
Thanks for any help with this!
Take Care... Mike.

J
Jane 11/28/2007

Mike,
you can add or remove fields from validation list editing your template on the Visual Editor tab --> HTML mode.

Here is a sample:

{literal}<script>

document.forms.editform.value_FieldName.onchange=function()

{

if($admin==1)

define('value_FieldName2','IsRequired','FieldName2: ');

else

undefine('value_FieldName2');

}

function undefine(n)

{

if (document.editform != null)

{

for (i = 0; i < checkObjects.length; i++)

{

if (checkObjects[i].form.name==n)

checkObjects.splice(i,1);

}

}

}

</script>{/literal}



where FieldName and FieldName2 are your actual field names.
To assign value to $admin variable use Add page: Before display event:

if ($_SESSION["UserID"]!="Guest")

$smarty->assign("admin",1);

else

$smarty->assign("admin",0);