HTML Form submission and handling in PHP
i need a help. actually i have a html form as sown below.
<form id="blog" class="" action="blog/save" method="POST">
<input type="text" id="blog[title]" class="" name="blog[title]" value="" />
<input type="text" id="blog[tag]" class="" name="blog[tag]" value="" />
<textarea id="blog[editor]" class="" name="blog[editor]"></textarea>
<input type="submit" id="blog[save]" name="blog[save]" class="button" value="Save Post" />
<input type="submit" id="blog[savePub]" name="blog[savePub]" class="button" value="Save & Publish Post" />
</form>
but in the php file i need to check which开发者_开发百科 submit button is clicked blog['save'] or blog['savePub']. and i tried like this
if ($_REQUEST['blog[save]']) {
echo $_POST['blog[title]'];
}
else if($_REQUEST['blog[savePub]') {
echo $_POST['blog[title]'];
}
but i am getting an error Notice: Undefined index: blog[save]
please help me to find a solution for this problem.
Thanks in advance... Wishes and Prayers.. Jaison Justus
try
if (isset($_POST['blog']['savePub']))
echo $_POST['blog']['editor'];
when you use [
and ]
in html form names PHP conveniently transforms them into sub arrays so you'll find your data at $_POST['blog']['title']
and $_POST['blog'][savePub']
etc
Try this,
if (isset($_POST['blog']['save'])) {
echo $_POST['blog']['title'];
}
else if(isset($_POST['blog']['savePub'])) {
echo $_POST['blog']['title'];
}
Try this
if (isset($_POST['blog']['save'])) {
echo $_POST['blog']['title'];
}
else{
echo $_POST['blog']['title'];
}
精彩评论