简体   繁体   中英

Radio button on click submit the form and send information to another file

this is my php code and i want to make when i push Radio button to make the form id prov submit like i have the the input submit button value="Shko Live". So i want when i push radio button on or off to submit form and to send the information to action="intervista-csv.php" method="post". Can anyone please help me ? :) Thank you

<?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>

See http://api.jquery.com/change/ & http://api.jquery.com/jquery.ajax/ For example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM