-2

I'm writing a form and this is its structure:

HTML:

<form method="post" action="script.php">
    <input type="text" name="nombre" >
    <input type="submit">
    <input type="submit">
</form>

PHP:

<?php
    if(isset($_POST))
    $options = array();
    $options[] = "";
    // here I use the value input in "name" text input, 
    // so I need to get it from the form
    for ($i=0;$i<=count($buscar)-1;$i++) {
        $options[] = "<option value='{$i}'>{$dato}</option>";
    }
    echo '<select class="" id="articles" size="1" name="articles">';
    echo implode("\n", $options);
    echo '</select>';
?>

Is there any way to tell the first submit to let the php be executed (because it creates a select item)?
Then, when the select is selected, click on the second submit and send the complete form?

Simple Sandman
  • 900
  • 3
  • 11
  • 34
minatoio
  • 1
  • 3

1 Answers1

3

You can do in two ways:

  1. Different Naming:

    <input type="submit" name="sub1" />
    <input type="submit" name="sub2" />
    

    And you can check it using:

    isset($_REQUEST["sub1"])
    isset($_REQUEST["sub2"])
    
  2. Passing Value:

    <input type="submit" name="sub" value="Submit Here" />
    <input type="submit" name="sub" value="Submit There" />
    

    And you can check it using:

    ($_REQUEST["sub"] == "Submit Here")
    ($_REQUEST["sub"] == "Submit There")
    
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252