How to disable submit button based on flagged column value of database?
Results 1 to 6 of 6

Thread: How to disable submit button based on flagged column value of database?

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    74

    How to disable submit button based on flagged column value of database?

    the following update form updates color preference of individual user in a password protected user area.

    PHP Code:
    $disable_switch '1';  
    //note: default value of $disable_switch= '0'; when user submits data using insert form primarily. when they update data using this update form the value changes to `1`

    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formX")) { 
    $updateSQL sprintf("UPDATE colortable SET color_name=%s, disable_switch=%s WHERE color_id=%s",    
                           
    GetSQLValueString($_POST['color_name'], "text"),
                           
    GetSQLValueString(trim($disable_switch), "int"),
                           
    GetSQLValueString($_POST['color_id'], "int"));

      
    mysql_select_db($database_XYZ$XYZ);
      
    $Result1 mysql_query($updateSQL$XYZ) or die(mysql_error());

      
    $updateGoTo "preference.php";
      if (isset(
    $_SERVER['QUERY_STRING'])) {
        
    $updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?";
        
    $updateGoTo .= $_SERVER['QUERY_STRING'];
          }
      
    header(sprintf("Location: %s"$updateGoTo));
        exit ();



    HTML Code:
    <form action="<?php echo $editFormAction; ?>" method="post" name="formX" id="formX">
    <table align="center">
      <tr valign="baseline">
        <td align="right" nowrap="nowrap">Update Color Name:</td>
        <td><input type="text" name="color_name" value="" size="32" /></td>
      </tr>
       <tr valign="baseline">
        <td nowrap="nowrap" align="right">
         <input type="hidden" name="MM_update" value="formX" />
        <input type="hidden" name="color_id" value="<?php echo $query['color_id']; ?>" />
         <input type="hidden" name="disable_switch" value="<?php echo "$disable_switch"; ?>" />
         </td>
         <td>
          < ?php 
            $disabled = "disabled";
            if (isset (which conditional statement shall disable the form permanently based on $disable_switch = '1'; ?)) {
            echo "<input type='submit' value='Update Color' " . $disabled . "/>";
            }else{
            echo "<input type='submit' value='Update Color'/>";
            } 
           ?>
                        </td>
                      </tr>
                    </table>
                  </form>
    by the way, i use the following mysql syntax to get the column values for disabling the submit button:

    Code:
    $query = "SELECT color_id, color_name, disable_switch FROM colortable WHERE color_id > 0 AND disable_switch = '1'";
    what conditional php statement i should use to disable the form as indicated html portion of this post?

    thanks,
    Last edited by polarexpress; 02-13-2013 at 03:36 AM.

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,420
    You'll probably want to use a comparison operator: operators.comparison.

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    74
    thanks for you guideline.

    i guess the following similar ternary operator which i implemented many times may serve my purpose:

    PHP Code:
    <?php
    $var
    ='<option value="1" '.($status == "1" 'selected="selected"' :'').'>Value 1</option>';
    echo 
    $var;
    ?>
    but i haven't find any reference about how to implement it with <input type='................'/> tag depending on the condition i described in my post. can you give me a reference about it?

    i can solve this problem in a lengthy way other than my expectation here.
    Last edited by polarexpress; 02-13-2013 at 05:08 AM.

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,420
    Quote Originally Posted by polarexpress View Post
    i haven't find any reference about how to implement it with <input type='................'/> tag depending on the condition i described in my post.
    What have you tried? It's the exact same concept; you've got a blob of text, some text that you want to conditionally include, and then another blob of text at the end.

    The only differences will be that the blob of text will look more like an <input> HTML entity rather than an <option>, and you'll be comparing the value of a different variable.

  5. #5
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,420
    Quote Originally Posted by polarexpress View Post
    i haven't find any reference about how to implement it with <input type='................'/> tag depending on the condition i described in my post.
    What have you tried? It's the exact same concept; you've got a blob of text, some text that you want to conditionally include, and then another blob of text at the end.

    The only differences will be that the blob of text will look more like an <input> HTML entity rather than an <option>, and you'll be comparing the value of a different variable.

  6. #6
    Member
    Join Date
    Apr 2012
    Posts
    74
    i've solved it the other way.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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