'Site name', 'required' => TRUE, 'maxlength' => 40, 'size' => 20, 'comment' => 'Site Information:'); $form['site:login_base'] = array('title' => 'Login base', 'required' => TRUE, 'maxlength' => 16, 'size' => 10); $form['site:abbreviated_name'] = array('title' => 'Abbreviated name', 'required' => TRUE, 'maxlength' => 20, 'size' => 12); $form['site:url'] = array('title' => 'URL', 'required' => TRUE, 'maxlength' => 30, 'size' => 30); $form['site:latitude'] = array('title' => 'Latitude', 'required' => FALSE, 'maxlength' => 10, 'size' => 10, 'type' => 'double'); $form['site:longitude'] = array('title' => 'Longitude', 'required' => FALSE, 'maxlength' => 10, 'size' => 10, 'type' => 'double'); $form['address:line1'] = array('title' => 'Address', 'required' => TRUE, 'maxlength' => 40, 'size' => 30, 'comment' => 'Postal address:'); $form['address:line2'] = array('title' => 'Address (2)', 'required' => FALSE, 'maxlength' => 40, 'size' => 30); $form['address:line3'] = array('title' => 'Address (3)', 'required' => FALSE, 'maxlength' => 40, 'size' => 30); $form['address:city'] = array('title' => 'City', 'required' => TRUE, 'maxlength' => 20, 'size' => 20); $form['address:postalcode'] = array('title' => 'Postal Code', 'required' => TRUE, 'maxlength' => 10, 'size' => 10); # would have liked it *not* required but it is mandatory in the DB - sigh $form['address:state'] = array('title' => 'State', 'required' => TRUE, 'maxlength' => 20, 'size' => 20); $form['address:country'] = array('title' => 'Country', 'required' => TRUE, 'maxlength' => 20, 'size' => 20); $form['pi:first_name'] = array('title' => 'PI First Name', 'required' => TRUE, 'maxlength' => 20, 'size' => 20, 'comment' => 'Principal Investigator Information:'); $form['pi:last_name'] = array('title' => 'PI Last Name', 'required' => TRUE, 'maxlength' => 20, 'size' => 20); $form['pi:title'] = array('title' => 'PI Title', 'required' => FALSE, 'maxlength' => 6, 'size' => 6); $form['pi:phone'] = array('title' => 'PI Phone', 'required' => TRUE, 'maxlength' => 20, 'size' => 20); $form['pi:email'] = array('title' => 'PI email', 'required' => TRUE, 'maxlength' => 40, 'size' => 20); if ($register_mode) { $form['pi:password'] = array('title' => 'PI password', 'required' => TRUE, 'maxlength' => 20, 'size' => 20, 'type' => 'password'); } if ($register_mode) { // required for the following code drupal_set_html_head(''); $fill_from_pi_button = <<< EOF EOF; } $form['tech:first_name'] = array('title' => 'Tech First Name', 'required' => TRUE, 'maxlength' => 20, 'size' => 20, 'comment' => 'Technical Contact Information:' . $fill_from_pi_button); $form['tech:last_name'] = array('title' => 'Tech Last Name', 'required' => TRUE, 'maxlength' => 20, 'size' => 20); $form['tech:title'] = array('title' => 'Tech Title', 'required' => FALSE, 'maxlength' => 6, 'size' => 6); $form['tech:phone'] = array('title' => 'Tech Phone', 'required' => TRUE, 'maxlength' => 20, 'size' => 20); $form['tech:email'] = array('title' => 'Tech email', 'required' => TRUE, 'maxlength' => 40, 'size' => 20); if ($register_mode) { $form['tech:password'] = array('title' => 'Tech password', 'required' => TRUE, 'maxlength' => 20, 'size' => 20, 'type' => 'password'); $form['tech:user-role'] = array('type' => 'boolean', 'title' => 'Need user role', 'default' => TRUE); } return $form; } // input : // $form : the form as defined above // $request : usually $_REQUEST // $input : a dict ('site'=>$site ..) // takes the values from the request and fills $input accordingly // output // $input : the modified dict, with as many keys as form categories, // + the 'is_empty' key that returns a boolean, FALSE if any field was set in the request function parse_form ($form, $request, $input = NULL) { if (empty ($input)) { $input = array(); } $empty_form = TRUE; // fill with values form the form foreach ($form as $fullname => $item) { list($objname,$field) = split(":",$fullname); $raw_input=$request[$fullname]; if (!empty($raw_input)) { $empty_form = FALSE; // implement type conversion switch ($item['type']) { case 'double': $input[$objname][$field] = doubleval(trim($raw_input)); break; case 'int': $input[$objname][$field] = intval(trim($raw_input)); break; case 'boolean': $input[$objname][$field] = ($raw_input=="yes"); break; case 'password': case 'raw': $input[$objname][$field] = $raw_input; break; default: $input[$objname][$field] = trim($raw_input); break; } } else { switch ($item['type']) { case 'double': $input[$objname][$field] = 0.0; break; case 'int': $input[$objname][$field] = 0; break; case 'boolean': if (array_key_exists($field,$request)) { $input[$objname][$field]=FALSE; } break; default: $input[$objname][$field] = ''; break; } } } $input['is_empty'] = $empty_form; return $input; } // checks all required fields are filled // returns a - possibly empty - html error string function form_check_required ($form, $input) { $missing = array(); foreach ($form as $fullname => $item) { list($objname,$field) = split(":",$fullname); if ($item['required'] && empty($input[$objname][$field])) { $missing[] = $item['title']; } } if (empty($missing)) return ""; $error = "