Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts

    Posting Without a Form

    Code:
    <fieldset class="submit">
    		<?php if ($site_exist >= 1){
    			echo "<input type=\"submit\" name=\"submit\" value=\"Update\">";
    		} else { echo "<input type=\"submit\" name=\"submit\" value=\"Submit\">";
    			} ?>
    <!-- The next line is the part in question -->
    		<input type="button" name="delete" value="Delete"
    			onClick="return confirmSubmit()">
    </fieldset>
    </form>
    		<script type="text/javascript"><!--
    			function confirmSubmit(){
    				var agree=confirm("Are you want to delete this site from our index?");
    				if (agree) return true ;
    				else return false ; } // -->
    		</script>
    Both the submit and the delete button are inside of a form. The submit button submits the form. The delete button is almost the same as the submit button, except instead of the form data I want it to post a separate, single variable (named delete or siteDelete and its value being true). I don't want to use javascript, the js code is only their to add a confirmation button.
    Last edited by djh101; 07-04-2010 at 01:57 AM.

  • #2
    New Coder
    Join Date
    Oct 2009
    Posts
    26
    Thanks
    2
    Thanked 1 Time in 1 Post
    Shouldn't this be in the PHP forum?

  • #3
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    No. There is PHP in my code, but my question is HTML related (PHP is required for retrieving data, my question is only about submitting data).

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    You can have as many as submit button inside a form but all the buttons will be submitted to the form action file only.

    There you can get the name of the button using isset($_POST['buttonname']) clicked and you can differentiate the functions that has to be done for the particular submitted or clicked button.

    Regards
    Ameen

  • #5
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    I don't want the delete button to submit the form, that's why I'm using type="button" instead of type="submit". What I want is for the button to post delete['true'] or delete="true" but only after javascript confirmation returns true. I was thinking something like
    Code:
    <input type="button" name="delete" value="Delete"
    	onClick="return confirmSubmit()" action="user.php?select=3">
    but I'm not sure how that would work, since value on buttons is used to determine their text rather than the value of their name and if the confirmation would work since it's inside the same tags as the action. If there is any way to have the button submit a form that it isn't contained in, that will work too- there's probably a hundred ways to make this work, I only need one way, be it with HTML, PHP, or javascript.

  • #6
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    I think the input is submitted as a variable with its value too. i.e. here:
    Code:
    <form action="http://example.com/" action="get">
      <fieldset>
        <legend>Setup</legend>
        <input id="update" name="update" value="Update" type="submit"/>
        <input id="delete" name="delete" value="Delete" type="submit"/>
      </fieldset>
    </form>
    Pressing the "delete" button would pass the variable "delete" with the value "Delete" to your processing script.

  • #7
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    So if I change it to
    <input id="delete" name="delete" value="Delete" type="button"
    onClick="return confirmSubmit()" action="user.php?section=3" method="post"/>
    would that work?

    And change
    $delete = $_POST['delete']
    if($delete=='true')
    to
    $delete = $_POST['delete']
    if($delete=='Delete')

  • #8
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Only way to know is to try.

  • #9
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    Nope. Is the onClick event considered active scripting? If all else fails I guess I'll have to use javascript, but I'd prefer for users to be able to delete their information without requiring it to be enabled.

  • #10
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    628
    Thanks
    51
    Thanked 67 Times in 67 Posts
    Wow, I guess for some reason it never occurred to me that submitting the form wouldn't be a problem, since it's just going to be deleted anyway. Problem Solved=D.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •