This topic is locked

Adding a required field to '_add'

4/6/2006 9:55:32 AM
PHPRunner General questions
C
crono999 author

I created a build of my system a while back, and have since highly modified its structure. I've added some fields to an "_add" page by playing with the code (adding to "_functions", "_add", etc.). Now I've been trying to make one of these new fields act as a required field, but I can't seem to get it to work. I've set it to return "True" in the function IsRequired in the "_functions" file, but all it does is add the required icon while still acting like a normal field. Any help would be appreciated. Thanks for the great product.

D
Dale 4/6/2006

Have you checked that you have added a define in the body onLoad function of your add and edit pages for this field.
Sample below.

<body onLoad="define('value1', 'IsRequired', 'Last Name(1)');

define('value10', 'IsPhoneNumber', 'Phone');

define('value11', 'IsPhoneNumber', 'Fax');">
This will then prompt you about the required field on saving.

C
crono999 author 4/6/2006

Thank you for the response, I've tried that but am now back to getting an error I had the last time I worked on this issue. When the page loads, and after saving, I get the following error (and it does nothing about the field being required):

"Runtime Error, Line: 3, Error: Object expected".
I just can't seem to figure out what this is refering to.

Sergey Kornilov admin 4/7/2006

Hi,
it seems that you make syntax mistakes in the code.

Please post modified code here and I'll help to find error.

C
crono999 author 4/7/2006

Well, before I post the entire code for the page, I just wanted to mention that the error only appears when I add this line in "<body >":
onLoad="define('value<?php echo array_search('contact_pref',$fieldlist);?>', 'IsRequired', '<?php echo Label('contact_pref');?>')"
I copied that (and just changed the field name) from another page I built that I had initially set to have required fields. Is there anything besides that line that I would need to add to the "_add" page?

Sergey Kornilov admin 4/7/2006

Hi,
the code looks correct.
Put this snippet just before the <body> tag:

<?php

include("include/validate.php");

?>


Also add

onSubmit=" return validate();"



attribute to

<form name="editform"...



tag.

C
crono999 author 4/7/2006

oh man... YOU ARE AWESOME! Thanks a lot, works perfectly now. I didn't even think to check for the validate call.