'title', 'text' => 'Title is a required field'); } if (empty($_POST['url'])) { $errors[] = array( 'field' => 'url', 'text' => 'URL is a required field'); } else if (!preg_match("/^(http(s?):\\/\\/|ftp:\\/\\/{1})((\w+\.)+)\w{2,}(\/?)$/i", $_POST['url'])) { $errors[] = array( 'field' => 'url', 'text' => 'URL must be a valid URL'); } if (empty($_POST['type'])) { $errors[] = array( 'field' => 'type', 'text' => 'Type is a required field'); } if (isset($errors)) { $template->adds_block('ISERROR',array('exi'=>1)); $eid = 0; foreach ($errors as $error) { $template->adds_block('ERROR', array( 'ID' => $eid, 'TEXT' => $error['text'])); $template->add('IS' . strtoupper($error['field']) . 'ERROR', ' error'); $template->adds_block(strtoupper($error['field']) . 'ERROR', array( 'ID' => $eid, 'TEXT' => $error['text'])); $eid++; } $template->add('TITLE', 'New Link'); $template->add('ACTION', '/admin/newLink.php?submit='); } else { $inslink = "INSERT INTO links (title,url,type) VALUES (\"" . mysql_real_escape_string($_POST['title']) . "\",\"" . mysql_real_escape_string($_POST['url']) . "\",\"" . mysql_real_escape_string($_POST['type']) . "\")"; $inslink2 = mysql_query($inslink); $template->adds_block('FLASH', array('TEXT' => 'Your link has been sucessfully created.')); $template->add('TITLE', 'Edit Link'); $template->add('ACTION', '/admin/editLink.php?id=' . mysql_insert_id() . '&submit='); $template->add('TYPEDISABLED', ' readonly="readonly"'); } $template->add('TITLEVALUE', htmlentities($_POST['title'])); $template->add('URLVALUE', $_POST['url']); $template->add(strtoupper($_POST['type']) . 'SELECTED', ' checked="checked"'); } else { $template->add('TITLE', 'New Link'); $template->add('ACTION', '/admin/newLink.php?submit='); } $template->display(); ?>