Viewed   69 times

please i need your help with an issue. I have two forms on my homepage that i'll like users to fill and submit at different times. My problem is that i'll like to have only one processing page for both of them. Normally i can do this in seperate pages. But i'll like to know if doing it on the same page is possible.

Okay.. If i submit form A, on the action page, wont there be Undefined Index for variable of form B, that has not being submitted, and ofcourse using a GET is not adviced.

Thanks for your time and patience.

 Answers

4

It's not completely unheard of to do this. Quite often, a different parameter is passed in the form element's action attribute like /submit.php?action=register or /submit.php?action=activate.

So, you have code like this:

if ($_GET['action'] == 'register') {
  // Register user
} else if($_GET['action'] == 'activate' {
  // Activate user
}

However, you could also just change the value of the submit button and have the action attribute the same for both forms:

if (isset($_POST['submit'])) {
  if ($_POST['submit'] == 'register') {
    // Register user
  } else if($_POST['submit'] == 'activate') {
    // Activate user
  }
}
Friday, November 18, 2022
3

It will submit the content encapsulated by the <form></form> tags. Having several form's action attribute point to the same page should not create the problem you describe.

The code you wrote here looks fine. Check your HTML code, and ensure you have the corrent <form></form> tags surrounding the elements of each form.

Friday, September 23, 2022
1

Try this:

<html><head><title>Connect to Database</title></head><body>
 <font size="4">Query gets Forename of nurse</font>
 <br><br><font size="4">Choose a name</font><br><br> 

 <form action="insert.php" method="post">
<select name="valuelist">;
<?php
$value=$_POST ["valuelist"];
$con = mysql_connect("localhost","root","") or die('Could not connect:'.mysql_error());
mysql_select_db("a&e", $con) or die('Could not select database.');

$fetch_nurse_name = mysql_query("SELECT DISTINCT Forename FROM nurse");


while($throw_nurse_name = mysql_fetch_array($fetch_nurse_name)) {
echo '<option   value="'.$throw_nurse_name[0].'">'.$throw_nurse_name[0].'</option>';
}
echo "</select>";


?>
<input type="submit" value="Submit">
</form></body></html>

Dont use mysql and mysqli together....you should use mysqli or PDO, but not a mix of both ;) PS: Edited ;)

Saludos.

Friday, October 14, 2022
 
4

I'm using this way :

if(empty($_GET['weightMin'])) {
    $weightMin= null;
} else $weightMin= $_GET['weightMin'];

if(empty($_GET['weightMax'])) {
    $weightMax= null;
} else $weightMin= $_GET['weightMax'];

And the statement would be :

SELECT * FROM TABLE 
WHERE ((weight >= :weighttMin AND weight <= :weightMax) OR (weight >= :weightMin AND :weightMax is null) OR (weight <= :weightMax AND :weightMin is null) OR (:weightMax is null AND :weightMin is null))

This is pretty long when it is x < filter < y

Else if this is only one type like 'Gender' :

if(empty($_GET['gender'])) {
    $gender = null;
} else $gender = $_GET['gender'];

The SQL:

SELECT * FROM TABLE
WHERE (gender = :gender or :gender is null)

If gender is selected, it will search the good one, else it returns true and doesn't impact your statement.

The combined query:

SELECT * FROM TABLE 
WHERE
((weight >= :weighttMin AND weight <= :weightMax) OR (weight >= :weightMin AND :weightMax is null) OR (weight <= :weightMax AND :weightMin is null) OR (:weightMax is null AND :weightMin is null))
AND
(gender = :gender or :gender is null)
Thursday, November 10, 2022
 
mmbs
 
5

The below code work for me

<?php
$config = require('config.php');
?>
<html>
  <head>
    <title>reCAPTCHA demo</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <!-- Boostrap Validator --> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.9/validator.min.js" ></script>

    <script type="text/javascript">
    $(document).ready(function(){
        var demo1Call = 0;
        var demo2Call = 0;

        $('#demo-form1').validator().on('submit', function (e) {
          if (e.isDefaultPrevented()) {
            // handle the invalid form...
            console.log("validation failed");
          } else {
            // everything looks good!
            demo1Call++;

            e.preventDefault();         
            console.log("validation success");

            if(demo1Call==1)
            {
                widgetId1 = grecaptcha.render('recaptcha1', {
                'sitekey' : '<?php echo $config['client-key']; ?>',
                'callback' : onSubmit1,
                'size' : "invisible"
                });
            }

            grecaptcha.reset(widgetId1);

            grecaptcha.execute(widgetId1);          
          }
        });

        $('#demo-form2').validator().on('submit', function (e) {
          if (e.isDefaultPrevented()) {
            // handle the invalid form...
            console.log("validation failed");
          } else {
            // everything looks good!
            demo2Call++;

            e.preventDefault();
            console.log("validation success");

            if(demo2Call==1)
            {
                widgetId2 = grecaptcha.render('recaptcha2', {
                'sitekey' : '<?php echo $config['client-key']; ?>',
                'callback' : onSubmit2,
                'size' : "invisible"
                });
            }

            grecaptcha.reset(widgetId2);

            grecaptcha.execute(widgetId2);

          }
        });

    });

    function onSubmit1(token){
            document.getElementById("demo-form1").submit();
    };

    function onSubmit2(token){
            document.getElementById("demo-form2").submit();
    };

    </script>


  </head>
  <body>
    <div class="container">
    <br>
        <div class="row">
            <div class="col-md-5 col-md-offset-3">
                <form id="demo-form1" data-toggle="validator" role="form"  action="admin.php" method="POST" >
                    <div class="form-group">
                        <label for="inputName" class="control-label">Name</label>
                        <input type="text" class="form-control" id="inputName" placeholder="Geordy James" required/>
                    </div>
                    <div id='recaptcha1' ></div>
                    <button class="btn btn-block btn-primary"  type="submit">Submit</button>
                </form>
            </div>
        </div>

    <br>
        <div class="row">
            <div class="col-md-5 col-md-offset-3">
                <form id="demo-form2" data-toggle="validator" role="form"  action="admin2.php" method="POST" >
                    <div class="form-group">
                        <label for="inputName" class="control-label">Name</label>
                        <input type="text" class="form-control" id="inputName" placeholder="Geordy James" required/>
                    </div>
                    <div id='recaptcha2' ></div>
                    <button class="btn btn-block btn-primary"  type="submit">Submit</button>
                </form>
            </div>
        </div>  
    </div>
    <script src="https://www.google.com/recaptcha/api.js" async defer ></script>
  </body>
</html>

I used Unofficial Google Invisible reCAPTCHA PHP library in this program and you can download it from https://github.com/geordyjames/google-Invisible-reCAPTCHA . If this method doesn't work for you please comment below.

Thursday, August 18, 2022
 
termie
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :