У меня есть форма отправления поста в блог. По какой то причине она отправлется только со второго клика.
Сама форма:
<form onsubmit="return savePost()" method="POST" id="post_form">
<table style="width:100%">
<tr>
<td>Название поста</td>
<td colspan=3><input style="width:100%" type="text" name="post_name"/></td>
</tr>
<tr>
<td>Текущий вес</td>
<td>
<input style="width:40px" type="text" name="weight" value="<?php
if ($page->db->getCountRows("m_weights","`user`='".$user_info['id']."'")>0)
{
$item_w=$page->db->toRow($page->db->getRows("m_weights",array('*'),"`user`='".$user_info['id']."'",Array("id DESC"),0,1));
echo $item_w['weight'];
}
else { if($user_info['weight']>0) echo $user_info['weight']; }
?>" onkeyup="this.value=this.value.replace(/[^\d\.]+/g,'')"/>
</td>
<td>Стадия</td>
<td>
<select style="width:236px; height:23px;" id="stage" name="stage">
<?php
if ($user_info['stage']>0)
{
$stage=$page->db->getRowById("m_stages_of_diet",$user_info['stage']);
}
$tmps=$page->db->getRows("m_stages_of_diet");
while($tmp=$page->db->toRow($tmps))
{
if ($stage['id']==$tmp['id']) echo '<option selected value="'.$tmp['id'].'">'.$tmp['name'].'</option>';
else echo '<option value="'.$tmp['id'].'">'.$tmp['name'].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td>Текст</td>
<td colspan=3><textarea style="width:100%;height:300px" class="CustomTextEditor17" name="post_text"></textarea>
<!--<img src="<?=$forum->sfolder;?>/).png" onclick="$('textarea[name=post_text]').insertAtCaret(':)');"/>
<img src="<?=$forum->sfolder;?>/(.png" onclick="$('textarea[name=post_text]').insertAtCaret(':(');"/>
<img src="<?=$forum->sfolder;?>/,).png" onclick="$('textarea[name=post_text]').insertAtCaret(':,)');"/>
<img src="<?=$forum->sfolder;?>/;).png" onclick="$('textarea[name=post_text]').insertAtCaret(';)');"/>
<img src="<?=$forum->sfolder;?>/7.png" onclick="$('textarea[name=post_text]').insertAtCaret(':/');"/>
<img src="<?=$forum->sfolder;?>/8).png" onclick="$('textarea[name=post_text]').insertAtCaret('8)');"/>
<img src="<?=$forum->sfolder;?>/D.png" onclick="$('textarea[name=post_text]').insertAtCaret(':D');"/>
<img src="<?=$forum->sfolder;?>/kiss.png" onclick="$('textarea[name=post_text]').insertAtCaret('*kiss*');"/>
<img src="<?=$forum->sfolder;?>/P.png" onclick="$('textarea[name=post_text]').insertAtCaret(':P');"/>
<img src="<?=$forum->sfolder;?>/O.png" onclick="$('textarea[name=post_text]').insertAtCaret(':O');"/>
<img src="<?=$forum->sfolder;?>/R.png" onclick="$('textarea[name=post_text]').insertAtCaret(':R');"/>
<img src="<?=$forum->sfolder;?>/X.png" onclick="$('textarea[name=post_text]').insertAtCaret(':X');"/>-->
</td>
</tr>
</table>
<input type="submit" value="Опубликовать" id=”myButton"/>
</form>
"
Функция savePost()
function savePost()
{
var t=true;
if ($('#post_form input[name=post_name]').val().length<1)
{
$('#post_form input[name=post_name]').css('background-color','#edc4c4');
t=false;
}
else $('#post_form input[name=post_name]').css('background-color','#ffffff');
if ($('#post_form textarea[name=post_text]').val().length<1)
{
$('#post_form textarea[name=post_text]').css('background-color','#edc4c4');
t=false;
}
else $('#post_form textarea[name=post_text]').css('background-color','#ffffff');
if (t)
{
var qString = $('#post_form').formSerialize();
$.post("/include/save_post.php", qString, function (data)
{
alert("Изменения сохранены");
top.location.href=top.location.href;
});
}
return false;
}
save_post.php
<?php
session_start();
include ($_SERVER['DOCUMENT_ROOT']."/Admin/modules/db.php");
include ($_SERVER['DOCUMENT_ROOT']."/Admin/modules/user.php");
$db=new data_base();
$db->connect();
$data['user']=$_SESSION['site_user'];
$user=new user($db,$data['user']);
$data['weight']=$_POST['weight'];
$data['stage']=$_POST['stage'];
$data['name']=$_POST['post_name'];
$data['text']=$db->strip_tags_smart($_POST['post_text'],array('br','p','td','th','li','h1','h2','h3','h4','h5','h6','div','title','pre','i','ul','ol','table','tr','img','strong','em'));
$data['date']=date("Y-m-d");
$data['time']=date("H:i:s");
$current_weight=$_POST['weight'];
if(!isset($_POST['blog']))
{
if (strlen($current_weight)>0) $db->addRow("m_weights",array('user'=>$data['user'],'weight'=>$current_weight,'date'=>date("Y-m-d")));
$user->updateUserInfo(array('stage'=>$data['stage'],'id'=>$data['user']));
//echo $data['stage'];
$db->addRow("m_blogs",$data);
}
else
{
$blog=$db->getRowById('m_blogs',$_POST['blog']);
if ((int)$_SESSION['site_user']==$blog['user'])
$db->updateRowById('m_blogs',$data,$_POST['blog']);
}
?>
Помогите пожалуйста!