单击单选按钮提交表单并将信息发送到另一个文件

时间:2014-02-04 10:36:32

标签: javascript php jquery html forms

这是我的PHP代码,我想在我按下单选按钮使表单id提交时提交,就像我有输入提交按钮值=“Shko Live”。所以当我按下单选按钮打开或关闭以提交表单并将信息发送到action =“intervista-csv.php”method =“post”时,我想要。谁能帮帮我吗 ? :)谢谢

<?php 
session_start(); /// initialize session 
include("../../passwords.php"); 
check_logged(); /// function checks if visitor is logged. If user is not logged the user is redirected to login.php page  
?>
<?php
    include ("../../includes/functions.php");    
    $pdo = new PDO('mysql:dbname=test;host=localhost', 'root', '',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
    $results  = $pdo->query('SELECT * FROM  `intervista80` WHERE  `delete` <> 1 ORDER BY  `id` DESC LIMIT 5')->fetchAll(PDO::FETCH_ASSOC);
    if (isset($_POST['ruaj']) && !empty($_POST['ruaj'])) {
        $pdo = new PDO('mysql:dbname=test;host=localhost', 'root', '',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
        $stmt = $pdo->prepare('INSERT INTO `intervista80` (`title`, `kronika`) VALUES (:title, :kronika)');
        $stmt->execute(array('title' => $_POST['title'], 'kronika' => $_POST['kronika']));
    header("Location: ".$_SERVER['PHP_SELF']."");
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Intervista 80 Panel</title>
<link rel="stylesheet" type="text/css" media="screen, projection, tv" href="../../css/style.css"/>
<script language="javascript" type="text/javascript">
function textCounter(field,cntfield,maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
        cntfield.value = maxlimit - field.value.length;
    }

function submitForm(formID) {
    document.getElementById(formID).submit();
    }

function setWTF(elementClicked) {
    if (elementClicked.value == 'Shto') {
        document.getElementById('wtf').value = 1;
    } else {
        document.getElementById('wtf').value = 2;
    }
}

</script>
</head>
    <div class="centered">
        <div class="wrapper">
            <form action="intervista-list.php" method="post" name="boto" target="_self" id="vendi">
<center>
            <a class="minimallive" href="intervista-nentitull-list.php" target="_self" />Live Nentitull</a>
            <a class="minimalshto" href="intervista-nentitull-shto.php" target="_self" />Shto Nentitull</a>
            <a class="minimallive" href="intervista-list.php" target="_self" />Live Titu/Kro</a>
            <a class="minimalshto" href="intervista-shto.php" target="_self" />Shto Titu/Kro</a>
            <a class="minimalmain" href="../../index.php" target="_self" />Main</a>

            <br /><br /><br />
            <a class="ndryshoblu" href="../../socket/scriptingintervista.php?id=11" target="_self" />Ndrysho Nentitull</a>
</center>   
            </form>
            <form action="#.php" method="POST" name="olform" target="_self" class="login" accept-charset="utf-8">
                <table>
                    <tr>
                    <td id="separator">
                        <input readonly="readonly" value="52" id="readonly" name="rem2" />
                        <label id="remaining">Karaktere te mbetura Titullin</label>
                    </td>
                    </tr>
                      <tr>
                        <td><textarea id="en-textarea" name="title" cols="52" rows="2" onkeydown="textCounter(this.form.title,this.form.rem,115);" onkeyup="textCounter(this.form.title,this.form.rem2,52);"></textarea></td>
                      </tr>
                    <tr>
                    <td id="separator">
                        <input readonly="readonly" value="12" id="readonly" name="rem3" />
                        <label id="remaining">Karaktere te mbetura Kronika</label>
                    </td>
                    </tr>
                      <tr>
                        <td><textarea id="en-textarea" name="kronika" cols="52" rows="2" onkeydown="textCounter(this.form.kronika,this.form.rem,115);" onkeyup="textCounter(this.form.kronika,this.form.rem3,12);"></textarea></td>
                      </tr>
                    <tr>
                    <td><input type="submit" name="ruaj" value="Ruaj"  /></td>
                    </tr>
                </table>
            </form>
            <form id="prov" action="intervista-csv.php" method="post" name="submit">                       
               <table>
                 <tr>
                   <th style="color:#900;">Titull</th>
                   <th style="color:#900;">Kronika</th>
                   <th style="color:#900;">Live</th>
                 </tr>
                 <?php $i=0; foreach ($results as $result) : ?>
                 <tr>
                   <td style="width:1200px;">
                   <input type="hidden" name="id<?php echo $i; ?>" value="<?php echo $result['id'] ?>" />
                   <input type="hidden" name="title<?php echo $i;?>"value="<?php echo htmlspecialchars($result['title'],ENT_NOQUOTES,'UTF-8');?>" />
                   <label style="font-size:16px;"><?php echo htmlspecialchars($result['title'],ENT_NOQUOTES,'UTF-8');?></label>
                   </td>
                   <td style="width:300px;">
                   <input type="hidden" name="id<?php echo $i; ?>" value="<?php echo $result['id'] ?>" />
                   <input type="hidden" name="kronika<?php echo $i;?>"value="<?php echo htmlspecialchars($result['kronika'],ENT_NOQUOTES,'UTF-8');?>" />
                   <label style="font-size:16px;"><?php echo htmlspecialchars($result['kronika'],ENT_NOQUOTES,'UTF-8');?></label>
                   </td>
                   <td style="width:300px">
                    <label><input type="radio" name="shfaq<?php echo $i; ?>" value="1" id="radiobuttonsondazh_0" <?php if($result['live']==1) echo 'checked'; ?> />Po</label>
                    <label><input type="radio" name="shfaq<?php echo $i; ?>" value="0" id="radiobuttonsondazh_1" <?php if($result['live']==0) echo 'checked'; ?> />Jo</label>            
                   </td>
                   <td style="width:250px">
                      <input type="checkbox" name="chk<?php echo $i; ?>" >Fshi
                   </td>
                  </tr>
                  <?php $i = $i+1;
                        endforeach;
                   ?>
                 </table>
                 <tr>
                   <td>&nbsp;</td>
                   <td>&nbsp;</td>
                   <td>&nbsp;</td>
                   <td><input style="margin-top:26px; margin-left:206px;" type="submit" name="submit" value="Shko Live"  /></td>
                 </tr>
                <input type="hidden" value="<?php echo $i = $i-1; ?>" name="saka" />              
            </form>
</div>
</div>
<body>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

http://api.jquery.com/change/&amp; http://api.jquery.com/jquery.ajax/例如:

$('#myradio').change(function(){
  // either
  $('#myform').submit();
  // or ajax
  var myform = $('#myform').serialize();
  $.ajax({
    url: "/mysubmit",
    type: "POST",
    data: myform
  });
});`