ok so Ive just switched hosts, n im finding oddly that forms which worked on the old host dont work on the new. ie.. pressing the submit button does nothing. Now on one or two of my forms id implemented a hidden field

<input type="hidden" name="_submit_check" value="1">

and id been saying

if (isset($submit) || array_key_exists('_submit_check', $_POST)) { //do stuff

and it seems those forms worked fine. so... what I really dont understand is WHY? Whats happening here? Is it correct to include a hidden field like this in all forms, even if they have several fields? I was only using it on forms where I had one field followed by a button so that hitting enter would submit the form. Alternately, is it ok for me to implement this on every form on my site? Would I be compromising my sercurity in any way by adding another condition under which said commands should be executed?

    I usually check my forms like so:

    <?php
    if(isset($_POST) && $_POST['submit'] == 'Submit')
    {
      // Submitted
    }
    else
    {
      // Not Submitted
    }

    And your form would be set up like:

    <input type="submit" name="submit" value="Submit">

    I check to see if the submit button has been checked. That's really all I've found I've needed. So hidden fields are not required.

      Thanks I'll give that a shot, that looks like a more practical way of doing it 🙂

        Grr.. what about with image links 😐

        I was using if ($submit_x) {

        but that concept doesnt seem to work with this way of doin it 😢

          For image links, just check to see if something you need has a value ($_GET most likely).

          If you're talking about submit buttons that are images, then just assign the button a name and value and chedk for that.

            I tried

            <input type="image" name="submit" src="grafix/delmessage.gif" width="11" height="12" alt="delete" value="Submit">
            <?php
            if (isset($_POST) && $_POST['submit'] == 'Submit') { 
            

            but nothing happens 🙁

              I take it the form is posting back to itself?

              This works, tested it myself. YOu can test it as well:

              <?php
              
              if(@isset($_POST) && !@empty($_POST['submit']))
              {
              	if($_POST['submit'] == 'imageSubmit')
              	{
              		echo '<strong>You clicked the Image Button!!</strong>';
              	}
              	if($_POST['submit'] == 'butSubmit')
              	{
              		echo '<em>You clicked the button Button!!</em>';
              	}
              	echo '<hr>';
              }
              
              ?>
              <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
              <input type="submit" name="submit" value="butSubmit">
              <input type="image" name="submit" value="imageSubmit" src="http://www.mozilla.com/images/firefox-logo-64x64.png" width="64" height="64">
              </form>

                Yea that should work shouldnt it? Its fine in Mozilla, but for some reason in Explorer nothing happens. Take a look please? I copied n pasted your code precisely as it is there...

                http://www.total-anarchy.com/dating_site/test.php

                n yea my forms meant to be posting back to the same page.. im trying to avoid having millions of unnecesarry pages n redirecting everywhere 🙂

                  Hmm.. this is interesting though because before I was getting away with

                  if (isset($submit_x))

                  and then I changed servers n this one either has a different version of php or something else disabled that I havent met before, but neway, im convinced it can be done... I guess Im gonna spend hours playin now lol... thanks for the help tho 🙂

                    AND THE ANSWER IS

                    <?php 
                    if(isset($_POST) && !empty($_POST['submit_x'])) { 
                    	 echo '<strong>You clicked the Image Button!!</strong><hr>'; 
                    } 
                    ?> 
                    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
                    <input type="image" name="submit" src="http://www.mozilla.com/images/firefox-logo-64x64.png" width="64" height="64"> 
                    </form>
                    

                    God I love it when things work.

                      Write a Reply...