我正在为wordpress开发一个插件,在一个函数中我有一个包含在页面中的表单!
问题是,当我点击更新按钮时,表单不会发送数据,当我收到消息时,我会再次获取表单(未更新)!
我的代码:
echo "<form method=\"POST\" action=\"". str_replace( '%7E', '~', $_SERVER['REQUEST_URI']) . "\">
<table>
<tr><td>Nume</td><td><input type=\"text\" name=\"nume\" value='".$data->name."'></td></tr>
<tr><td>Departament</td><td><input type=\"text\" name=\"dep\" value='". $data->dep."'></td></tr>
<tr><td>An</td><td>
<input type=\"text\" name=\"an\" id=\"an\" value='".$data->anfac."'>
<span style=\"margin:0 5px;\">Edit</span>
<select name=\"anv\" id=\"anv\">
<option value=\"Anul I\">Anul I</option>'
<option value=\"Anul II\">Anul II</option>
<option value=\"Anul III\">Anull III</option>
<option value=\"Anul IV\">Anul IV</option>
<option value=\"Master Anul I\">Master Anul I</option>
<option value=\"Master Anul II\">Master Anul II</option>
</select>
<script>
jQuery(document).ready(function() {
jQuery(\"#anv\").change(function(){
var valoare = jQuery(this).val();
jQuery(\"#an\").val(valoare);
});
});
</script>
</td></tr>
<tr><td>Grupa</td><td><input type=\"text\" name=\"grupa\" value='". $data->grupa ."'></td></tr>
<tr><td>Telefon</td><td><input type=\"text\" name=\"tel\" value='". $data->telefon."'></td></tr>
<tr><td>Email</td><td><input type=\"text\" name=\"email\" value='".$data->mail."'></td></tr>
<tr><td>Facebook</td><td><input type=\"text\" name=\"fb\" value='".$data->fb."'></td></tr>
<tr><td>Twitter</td><td><input type=\"text\" name=\"tw\" value='".$data->tw."'></td></tr>
<tr><td>LinkedIn</td><td><input type=\"text\" name=\"linked\" value='". $data->li."'></td></tr>
<tr><td>Freelancer</td><td><input type=\"text\" name=\"freel\" value='".$data->freel."'></td></tr>
<tr><td>Blog</td><td><input type=\"text\" name=\"blog\" value='". $data->site."'></td></tr>
<tr><td>Membru din anul</td><td><input type=\"text\" name=\"memyear\" value='".$data->an."'></td></tr>
<tr><td>Functii in LSE</td><td><textarea name=\"memfct\" id=\"\" cols=\"30\" rows=\"10\" value='".$data->fct."'>".$data->fct."</textarea></td></tr>
<tr><td>Evenimente</td><td><textarea name=\"evlse\" id=\"\" cols=\"30\" rows=\"10\" value='".$data->ev."'>".$data->ev,"</textarea></td></tr>
<tr><td>Skills</td><td><textarea name=\"skills\" id=\"\" cols=\"30\" rows=\"10\" value='".$data->skills."'>". $data->skills."</textarea></td></tr>
<tr><td>Avatar</td><td><input type=\"text\" name=\"avatar\" value='".$data->av ."'></td></tr>
<tr><td>CV</td><td><input type=\"text\" name=\"cv\" value='".$data->cv."'></td></tr>
<input type=\"hidden\" value='".$data->id."' name=\"id\">
<tr><td><input type=\"submit\" value=\"Update\" name=\"update1234\"></td></tr>
</table>
</form>";
和数据“捕手”:
elseif (isset($_POST['update1234'])) {
$nume = mysql_real_escape_string($_POST['nume']);
$dep = mysql_real_escape_string($_POST['dep']);
$an = mysql_real_escape_string($_POST['an']);
$grupa = mysql_real_escape_string($_POST['grupa']);
$tel = mysql_real_escape_string($_POST['tel']);
$email = mysql_real_escape_string($_POST['email']);
$fb = mysql_real_escape_string($_POST['fb']);
$tw = mysql_real_escape_string($_POST['tw']);
$linked = mysql_real_escape_string($_POST['linked']);
$freel = mysql_real_escape_string($_POST['freel']);
$blog = mysql_real_escape_string($_POST['blog']);
$memyear = mysql_real_escape_string($_POST['memyear']);
$fct = mysql_real_escape_string($_POST['memfct']);
$evlse = mysql_real_escape_string($_POST['evlse']);
$skills = mysql_real_escape_string($_POST['skills']);
$avatar = mysql_real_escape_string($_POST['avatar']);
$cv = mysql_real_escape_string($_POST['cv']);
$id = mysql_real_escape_string($_POST['id']);
$editlink = generate_edit_link();
$sql ="UPDATE $lmdisp_table_name
SET `".$lmdisp_nume."`= '".$nume."',
`".$lmdisp_departament."` = '".$dep."',
`".$lmdisp_an."` = '".$an."',
`".$lmdisp_grupaserie."` = '".$grupa."',
`".$lmdisp_tel."` = '".$tel."' ,
`".$lmdisp_email."` = '".$email."',
`".$lmdisp_fb."` = '".$fb."',
`".$lmdisp_tw."` = '".$tw."',
`".$lmdisp_linked."` = '".$linked."',
`".$lmdisp_freel."` = '".$freel."',
`".$lmdisp_blog."` = '".$blog."',
`".$lmdisp_memyear."` = '".$memyear."',
`".$lmdisp_fctlse."` = '".$fct."',
`".$lmdisp_evlse."` = '".$evlse."',
`".$lmdisp_skills."` = '".$skills."',
`".$lmdisp_avatar."` = '".$avatar."',
`".$lmdisp_cv."` = '".$cv."',
`".$lmdisp_editlink."` = '".$editlink."'
WHERE `".$lmdisp_id."` = '".$id."'";
if ($wpdb->query($sql)) {
echo "Date modificate";
} else {
echo "S-a produs o eroare";
}
$wpdb->show_errors();
$wpdb->print_error();
}
else {
echo 'Nu ar trebui sa fii aici';
}
答案 0 :(得分:1)
我测试了提供的示例,一切正常,表单已发送。我注意到的唯一事情是'catcher'示例是if-elseif块的延续,因此它可能是一个逻辑错误,并且第一个块再次执行。尝试:
if ( isset($_POST['update1234']) ) {
// save data
} else {
// render form
}