Добрый день. имеется форма с полями по кнопки происходит запись в БД и перегружается страница, задача стоить чтобы проверить все ли поля заполнены. пока что проверяю тока на заполнение поля NAME , сообщение выдается что не заполнено но все равно сабмит срабатывает. кто сможет подсказать.?
<?php
/**
* Hotspots - Frontend
* @package Joomla!
* @Copyright (C) 2009 Yves Hoppe - lunajoom.de
* @All rights reserved
* @Joomla! is Free Software
* @Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version $Revision: 0.9.4 beta $
**/
defined( '_JEXEC' ) or die ( 'Restricted access' );
if (HotspotsHelper::getSettings(addhs_front, 1) == "1")
{
if ($this->display_addform == 1) {
?>
<br />
<?php
if (HotspotsHelper::getSettings(addhs_map, 1) == "1")
{
?>
<div onload="initialize()" style="width:100%; overflow:hidden;">
<div id="map_add" style="width: 100%; height: 300px;"></div><br />
<?php echo JText::_('MOVE_MARKER_DRAG'); ?>
</div>
<br />
<br />
<?php
}
?>
<script type="text/javascript">
function initialize() {
var map = new GMap2(document.getElementById(map_add"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
GEvent.addListener(map,"click", function(overlay, latlng) {
if (latlng) {
var myHtml = "The GPoint value is: " + map.fromLatLngToDivPixel(latlng) + " at zoom level " + map.getZoom();
map.openInfoWindow(latlng, myHtml);
}
});
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
}
</script>
<script type="text/javascript">
function text (str) { return /[0-9_;:'!<=+<|>]/g.test(str); }
function checkForm()
{
var title;
var elem;
var dutyField = "Не заполнено поле ";
var wrongField = "Неверное значение поля ";
var check = true;
function checkError (field, str)
{
check = false;
document.getElementById("alert").innerHTML = str;
document.forms.adminForm.field.focus();
}
document.getElementById("alert").innerHTML = "";
if (check)
{
title = '"Контактное лицо"';
elem = document.adminForm.name.value;
if (elem.length == 0) checkError('name', dutyField + title);
else if (text(elem)) checkError('name', wrongField + title);
}
return check;
}
</script>
<form action="index.php" method="post" onsubmit="return checkForm()" name="adminForm" id="adminForm" enctype="multipart/form-data">
<fieldset class="adminform">
<table class="admintable">
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('category'); ?>:
</td>
<td>
<?php
echo $this->lists['categories'];
?>
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<?php echo JTEXT::_('Hotspot_name'); ?>:
</td>
<td>
<input class="text_area" type="text" name="name" id="name" size="50" maxlength="250" value="" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key" style="padding-left: 20px;">
<?php echo JText::_('Your Name'); ?>:
</td>
<td>
<input class="text_area" type="text" name="autor" id="autor" size="50" maxlength="250" value="<?php echo getUsername();?>" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('Your E-Mail'); ?>:
</td>
<td>
<input class="text_area" type="text" name="autor_mail" id="autor_mail" size="50" maxlength="250" value="<?php echo getUseremail();?>" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('street'); ?>:
</td>
<td>
<input class="text_area" type="text" name="street" id="street" size="70" maxlength="250" value="" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('short_description'); ?>:
</td>
<td>
<textarea class="text_area" cols="20" rows="4" name="description_small" id="description_small" size="70" value="" style="width:320px" /></textarea>
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('long_description'); ?>:
</td>
<td>
<textarea class="text_area" cols="20" rows="8" name="description" id="description" size="70" value="" style="width:320px" /></textarea>
</td>
</tr>
<?php
if (HotspotsHelper::getSettings(addhs_picture, 0) == "1")
{
?>
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('picture'); ?>:
</td>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="file" name="picture" id="picture" />
</td>
</tr>
<?php
}
if (HotspotsHelper::getSettings(addhs_picture, 0) == "2") {
$user =& JFactory::getUser();
if($userid->_table->id)
{
?>
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('picture'); ?>:
</td>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="file" name="picture" id="picture" />
</td>
</tr>
<?php
} else {
echo "<tr><td align=\"right\">" . JText::_('picture'). ": </td><td>";
echo JText::_('need_to_register_pic');
echo "</td></tr>";
}
}
/* --- CAPTCHA ---- */
if (HotspotsHelper::getSettings(addhs_captcha, 1) == 1)
{
?>
<tr>
<td width="100" align="right" class="key">
<?php echo JText::_('Captcha'); ?>:
</td>
<td>
<?php
function randomString($len) {
function make_seed(){
list($usec , $sec) = explode (' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$possible="ABCDEFGHJKLMNPRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
$str="";
while(strlen($str)<$len) {
$str.=substr($possible,(rand()%(strlen($possible))),1);
}
return($str);
}
header('Content-type: image/png');
$imagepath = (JPATH_BASE.'/components/com_hotspots/captcha/');
$captchatext = randomString(5);
$img = ImageCreateFromPNG(JPATH_BASE.'/components/com_hotspots/captcha/captcha.PNG');
$color = ImageColorAllocate($img, 0, 0, 0); //Farbe
$ttf = (JPATH_BASE.'/components/com_hotspots/captcha/XFILES.TTF');
$ttfsize = 25;
$angle = rand(0,5);
$t_x = rand(5,30);
$t_y = 35;
imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $captchatext);
if (!file_exists($imagepath . md5($captchatext). '.png'))
{
imagepng($img, $imagepath . md5($captchatext). '.png');
}
?>
<input type="text" name="captcha" id="captcha" size="5"> <img src="<?php echo 'components/com_hotspots/captcha/' . md5($captchatext). '.png' ?>" border="0" title="Captchacode" style="vertical-align:middle;" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<?php echo JText::_('captcha_hint'); ?>
</td>
</tr>
<?php
}
?>
<tr>
<td>
</td>
<td align="right">
<br />
<p class="red" id="alert"></p>
<input type="submit" class="button" id="button" value="Добавить" />
</td>
</tr>
</table>
</fieldset>
<input type="hidden" name="option" value="com_hotspots" />
<input type="hidden" name="controller" value="hotspots" />
<input type="hidden" name="view" value="all" />
<input type="hidden" name="model" value="all" />
<input type="hidden" name="task" value="addhotspot" />
<input type="hidden" name="autoruserid" value="<?php echo $user->id; ?>" />
<input type="hidden" name="ckey" value="<?php echo md5($captchatext); ?>" />
<input type="hidden" name="gmlng" id="gmlng" value="" />
<input type="hidden" name="gmlat" id="gmlat" value="" />
</form>
<?php
// DEBUG FUNKTION
if (HotspotsHelper::getSettings(debug, 0) == 1) {
echo "<div id=\"message2\"></div>\n";
}
} else {
if ($this->allowed_user == 1) {
echo JText::_('need_to_register');
} else {
echo JText::_('no_rigths');
}
}
}
?>