0

Hello I have many inputs radiobutton but i don't need to send them all to my insert php. How can I choose some input and send it to another page with one button ?

MY code is very long

something like this x7

This is my autocomplete page

<!-- fonction doubler la rangꥠdu dimanche -->   

<div >
    <form method="post"  >
        <div id="itemRows">
            <?php
            if ($result != false && mysqli_num_rows($result) > 0) {
                while ($product = mysqli_fetch_array($result)):
                    ?>
                    <p id="oldRow<?= $product['id'] ?>">    <input type="text" name="client1<?= $product['id'] ?>" size="4" value="<?= $product['client1'] ?>" />   <input type="text" name="name<?= $product['id'] ?>" value="<?= $product['name'] ?>" />  </p>
                <?php
                endwhile;
            }
            ?>
        </div>
    </form>
</div>
</td>

<!-- client du dimanche -->
<td>
    <span id="proclient">   
        <input type="text" name="client1" size="12" class = "client1"  id ="client1" disabled />    
    </span>
</td>
<!-- description du projet de dimanche -->
<td>
    <span id="prodesc">
        <input type="text" name="desc1" size="30" id ="desc1" class "desc" disabled />
    </span>
</td>
<!-- ddescription de la tache du dimanche -->
<td>
    <span id="protache">
        <textarea rows="1" cols="20" name="taskDesc1" id ="task1" class "task"> </textarea>
    </span>
</td>
<!-- lieu pour dimanche -->
<td>
    <span id="prolieu">
        <input type="text" name="prolieu1" size="10" id ="lieu1" class "lieu">
    </span> 
</td>   

<!-- tache  -->     
<td>
    <span id="tache">
    <!--    <input type="text"  name="tache" size="30" id="tache"class= "tache"  />  -->    
        <!-- dꣵt section combobox tache avec tool tip -->                   
        <label title="Select your state"> <select title="Select your state" id="state" name="state">
                <?php
                $stmt->execute();
                while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                    echo ' <option title="';
                    echo $row['tacName'];
                    echo '">';
                    echo $row['tacId'];
                    echo '</option>' . "\n";
                    $task = array();
                }
                ?>
            </select>
        </label>
        <!-- Fin section cobobox tache avec tool tip -->        
    </span>
</td>

<!-- calculter le temps pour le diamnche -->        
<td>
    <span id="calculTemps">
        <input type="number" id="input1"  class="temps"  name="tempsdi" size="10" min="0" max="24" value="0"/><br/>
    </span>
</td>
<br>

like I said i don' need to send all value of the input, how do I choose the one I need?

EDIT Here is theinsert php, I want to take some VAR from my autocomplete cause I will insert them to the database afterwards.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
    <LINK rel=stylesheet type="text/css" href="main.css">




    <?php

    session_start(); 
    $client1 = $_POST['client1'] ;
// Connect to the DB
    $link = mysqli_connect("localhost","root","","cruel") or die("Error " . mysqli_error($link));


    // adding new recherche
    if(!empty($_POST['name'])) 
    {
        foreach($_POST['name'] as $name)
        {
        // THIS IS NOTÉ FINISH MY INSERT AND NEED TO BE MODIFY LATER

            $sql = "INSERT INTO recherche (name) VALUES ('".mysqli_real_escape_string($link,$name)."')";
            $link->query($sql);
        }
    } 


$date = $_POST['data'] ;


echo($client1);
echo($date);




?>
user3241019
  • 811
  • 9
  • 20

3 Answers3

0

The <form> and </form> tag determines which inputs will be sent to the server, being every input tag between those tags. If you want to send only a selection of inputs you can create multiple HTML forms on a single page. You'll need a submit button in every one though, and form tags cannot be nested in other form tags.

Plenka
  • 1,099
  • 7
  • 17
0

Any input that has a name attribute will be sent. If you don't want to send a specific input, just make sure it has no name attribute and ensure those that are needed do have one.

EDITED: Following some comments to the original post, and my answer and your updated code, here is what I propose.

Your problem is not only with the fact that you cannot selectively send something to your "insert php" but the fact that you're actually not sending anything it correctly.

First of all, make sure your form attributes wrap all the fields that you do want to send, ie. anything below <!-- client du dimanche --> is not currently sent as they are outside the form tags.

Second, on your "insert php", doing foreach($_POST['name'] as $name) won't work as foreach is there to iterate over arrays, but $_POST['name'] is going to output a value of the array $_POST, thus your foreach loop will most probably fail. Nonetheless you don't even have an input on your original page with name=name so you're looking for the wrong one and I believe you just don't necessarily understand the difference between attributes and indexes.

So let me explain: the name part on an input field is an attribute, whatever it has as a value will become the index of the array $_POST on the page you're sending the form to. In your example, provided (and only if) you do wrap those other inputs inside your form tags, client1, desc1... will become indexes of $_POST, like this: $_POST['client1'] for example.

I believe what you're trying to achieve is a little more complicated and is not in the scope of this question, so all I can recommend you to do is to lookup some basic tutorials on mysqli and follow them. One of such could be http://codular.com/php-mysqli.

benomatis
  • 5,536
  • 7
  • 36
  • 59
  • I think if you add the disabled attribute, on the fly, it will have the same effect – py_script Apr 09 '14 at 17:22
  • diasabled cause i have a autocomplete function. and do you have a exemple if i just want to send exemple my client, project but no other thing? – TheBaconManWithouBacon Apr 09 '14 at 17:25
  • @py_script Why don't you add it as a response? it's also a possible one! – benomatis Apr 09 '14 at 17:26
  • @TheBaconManWithouBacon Do you mean your autocomplete function needs the `name` attribute? if so, you might as well go with disabling the ones that you don't need, as @py_script suggested. – benomatis Apr 09 '14 at 17:28
  • my autocomplete with ID and enter pressed. – TheBaconManWithouBacon Apr 09 '14 at 17:29
  • I'm guessing that the inputs will point to other functionality which is why you need them without being sent to the db, so disabling them would not be an option, correct? ok, so did you try simply removing their `name` attribute? – benomatis Apr 09 '14 at 17:30
  • If I remove their name i could send the one I want to insert.php? – TheBaconManWithouBacon Apr 09 '14 at 17:36
  • remove `name` = will NOT be sent --- keep `name` = WILL be sent ;) – benomatis Apr 09 '14 at 17:38
  • I understand the diffence of a index or attribute. I just don't understand how could I send witch I need . If i could send all input with a specific tag. – TheBaconManWithouBacon Apr 09 '14 at 18:15
  • and what is the link of mysqi? I'm not talking of my database for the moment I know how to do it – TheBaconManWithouBacon Apr 09 '14 at 18:20
  • @TheBaconManWithouBacon I don't think your question was about how to send data to the DB via MySQLi, correct? well, the problem is that you're doing it incorrectly, as detailed in my answer... try fixing it following my instructions and add a new question if you're stuck... – benomatis Apr 09 '14 at 18:23
  • I said as comment mysqli was not finish i didn't fix it and didn't work it for the moment my only question was how do i send 4 of my 50 input to insert.php so after i'll work mysqli. So I don't know why for the moment you're talking of mysqi if that was not my question – TheBaconManWithouBacon Apr 09 '14 at 18:39
0

I think that if you add the disabled attribute, on the fly, to the fields you do not want to include on the request, it will have the desired effect.

For example:

document.getElementById("my_target_element").disabled = true;

There is a similar question here, where the OP, doesn't want that effect. Worth taking a look

Disabled form inputs do not appear in the request

Hope it helps...

Community
  • 1
  • 1
py_script
  • 808
  • 2
  • 16
  • 38