Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2

    One form button two function


    I have a form with a checkbox and an image button. If the check box isnt selected then the user gets an alert. if the tick box is selected and they submit the button they are sent to a new page. I need another function aswell. when the tick box is check and the button is selected i need for the information for the checkbox (1) to be sent the the DB (mySQL),

    this is what i have currently

    Code:
    <form action="eLease.php?userid=<?php echo $row_Recordset1['userid']; ?>" method="post" name="form2" target="_new" id="form2">
    <div align="right"><span id="sprycheckbox2">
    <span class="body-text">Lease Schedule</span>
    
    <input type="image" src="../images/smalldownload.png" width="35" height="35" alt="download" value="submit"/>
    </a>
    <input type="checkbox" name="leaseshedule" id="leaseshedule" />
    
    
    </span></div>
    </form>
    <div id="ErrorZone1"><span class="checkboxRequiredMsg"><table width="400" border="1" cellspacing="0" cellpadding="0">
    <tr>
    <td><table width="400" border="0" cellspacing="10" cellpadding="0">
    <tr>
    <td><strong>Electronic Agreement:</strong>
    </td>
    </tr>
    <tr>
    <td>By you ticking the box above 'TickBox',you agree to the terms</td>
    </tr>
    <tr>
    <td><strong>Terms and Conditions</strong></td>
    </tr>
    <tr>
    <td>I have read and understand the statement above</td>
    </tr>
    </table></td>
    </tr>
    </table>
    </span></div>

    thanks
  2. #2
  3. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    That's a very nice form but you need to show us the processing code, oh and also, USE PHP TAGS AROUND THE CODE!!!!

    There's even a sticky that says to do that!
    OMGROFLCOPTERBBQHAX
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2
    Originally Posted by badger_fruit
    That's a very nice form but you need to show us the processing code, oh and also, USE PHP TAGS AROUND THE CODE!!!!

    There's even a sticky that says to do that!
    OMGROFLCOPTERBBQHAX

    sorry about that, added tags now

    well currently i will just be

    PHP Code:
    if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
      
    $updateSQL sprintf("UPDATE plus_signup SET signed=%s WHERE userid=%s",
                           
    GetSQLValueString($_POST['signed'], "text"),
                           
    GetSQLValueString($_POST['userid'], "text"));

      
    mysql_select_db($database_host$host);
      
    $Result1 mysql_query($updateSQL$host) or die(mysql_error()); 
    thanks
  6. #4
  7. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    You need to add an IF statement somwhere in the processing code to determine IF the checkbox was checked or not.
    Take this simple script for example:-

    PHP Code:
    <?php

    echo "<form name='chk' method='post'>";
    echo 
    "<input type='checkbox' name='test' value='badger'>";
    echo 
    "<input type='submit' name='submit' value='Submit'>";
    echo 
    "</form>";

    if (isset(
    $_POST['test'])) {
        echo 
    "The checkbox was selected!";
    } else {
        echo 
    "The checkbox was not selected!";
    }

    ?>
    I use something similar in my real-life code, I won't bore you with it but hopefully from that example above, you can see what's going on and make the appropriate modifications so you can use it in your processing page.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  8. #5
  9. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Oh, the same idea can be used if you use RADIO buttons instead of checkboxes, just make the IF statement read something like:-

    PHP Code:
     <?php

    echo "<form name='chk' method='post'>";
    echo 
    "<input type='radio' name='test' value='badger' id='badger'> <label for='badger'>BADGER</label><br />";
    echo 
    "<input type='radio' name='test' value='fruit' id='fruit'> <label for='fruit'>FRUIT</label><br />";
    echo 
    "<input type='submit' name='submit' value='Submit'>";
    echo 
    "</form>";

    if (
    $_POST['test'] == "badger") { echo "BADGER was selected!"; }
    if (
    $_POST['test'] == "fruit") { echo "FRUIT was selected!"; }

    ?>
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    12
    Hi,

    well, I think what he actually wanted to know is how to save the value of the checkbox in the database. I don't know if this is legally OK, but how about simply putting a constant "1" in the INSERT query? If the checkbox isn't checked, then the user doesn't get through in the first place, right? (Assuming you check this with PHP and not only JavaScript, which can be deactivated).
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2
    Originally Posted by badger_fruit
    You need to add an IF statement somwhere in the processing code to determine IF the checkbox was checked or not.
    Take this simple script for example:-

    PHP Code:
    <?php

    echo "<form name='chk' method='post'>";
    echo 
    "<input type='checkbox' name='test' value='badger'>";
    echo 
    "<input type='submit' name='submit' value='Submit'>";
    echo 
    "</form>";

    if (isset(
    $_POST['test'])) {
        echo 
    "The checkbox was selected!";
    } else {
        echo 
    "The checkbox was not selected!";
    }

    ?>
    I use something similar in my real-life code, I won't bore you with it but hopefully from that example above, you can see what's going on and make the appropriate modifications so you can use it in your processing page.
    @badger_fruit ok thanks i will try what you have suggested and post how i get on
  14. #8
  15. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Originally Posted by Jacques3
    Hi,

    well, I think what he actually wanted to know is how to save the value of the checkbox in the database. I don't know if this is legally OK, but how about simply putting a constant "1" in the INSERT query? If the checkbox isn't checked, then the user doesn't get through in the first place, right? (Assuming you check this with PHP and not only JavaScript, which can be deactivated).
    Ah, maybe, I replied to what I thought was the question but maybe you're right ... either way, he'll need an IF statement to first check if it was selected or not and then use the condition to either create a new bit of SQL or modify his existing one to set the field to an appropriate value.

    PHP Code:
    if (isset($_POST['checkboxname']) {
      
    $opt_in 1;
    } else {
      
    $opt_in 1;
    }
    $sql "INSERT INTO `tablename` (`its`, `friday`) VALUES (0,{$opt_in})"
    Or something like that anyway
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2
    Originally Posted by Jacques3
    Hi,

    well, I think what he actually wanted to know is how to save the value of the checkbox in the database. I don't know if this is legally OK, but how about simply putting a constant "1" in the INSERT query? If the checkbox isn't checked, then the user doesn't get through in the first place, right? (Assuming you check this with PHP and not only JavaScript, which can be deactivated).

    so have the value of o in the db and on the landing page say
    if
    signed = 0 the direct to incorrect page but if = 1 then direct to correct page?
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2
    Originally Posted by badger_fruit
    Ah, maybe, I replied to what I thought was the question but maybe you're right ... either way, he'll need an IF statement to first check if it was selected or not and then use the condition to either create a new bit of SQL or modify his existing one to set the field to an appropriate value.

    PHP Code:
    if (isset($_POST['checkboxname']) {
      
    $opt_in 1;
    } else {
      
    $opt_in 1;
    }
    $sql "INSERT INTO `tablename` (`its`, `friday`) VALUES (0,{$opt_in})"

    Or something like that anyway
    Getting a bit confused here...

    right i have a button and a check box..

    currently if the checkbox isnt checked and the user presses the button they get an alert. If the checkbox is check they get directed to another page. I also need (when submitted) to send the checkbox info to the DB.

    will the above code acheive this??

    thanks
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2
    Originally Posted by badger_fruit
    Ah, maybe, I replied to what I thought was the question but maybe you're right ... either way, he'll need an IF statement to first check if it was selected or not and then use the condition to either create a new bit of SQL or modify his existing one to set the field to an appropriate value.

    PHP Code:
    if (isset($_POST['checkboxname']) {
      
    $opt_in 1;
    } else {
      
    $opt_in 1;
    }
    $sql "INSERT INTO `tablename` (`its`, `friday`) VALUES (0,{$opt_in})"

    Or something like that anyway
    Getting a bit confused here...

    right i have a button and a check box..

    currently if the checkbox isnt checked and the user presses the button they get an alert. If the checkbox is check they get directed to another page. I also need (when submitted) to send the checkbox info to the DB.

    will the above code achieve this??

    thanks
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    57
    Rep Power
    12
    I find it hard to understand what you want to do and what you're struggling with. Could you try to make yourself more clear?

    OK, so you have a form with a checkbox. If the user doesn't check the checkbox, he cannot submit and instead gets a JavaScript message. Right? And if he does submit, you again check if the checkbox is active in case he has deactivated JavaScript or simply "forged" the request. Right?

    Now what's the problem? How to write an "if" statement to check the value of the checkbox? You already have a similar check in your current code, and badger_fruit said exactly what you have to do (check for isset).

    Or do you not know how to save the value in the database? That would be a bit strange, because you already have some queries in your code, so you obviously know how it works. What I asked before is why you need to save the checkbox value in the first place. Isn't it always 1? I assume that you do not insert anything in the database if the user hasn't checked the checkbox.
  24. #13
  25. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    Oops, I made a mistake when I wrote the last post:-

    PHP Code:
    if (isset($_POST['checkboxname']) {
      
    $opt_in 1;
    } else {
      
    $opt_in 1;
    }
    $sql "INSERT INTO `tablename` (`its`, `friday`) VALUES (0,{$opt_in})"
    SHOULD read

    PHP Code:
    if (isset($_POST['checkboxname']) {
      
    $opt_in 1;
    } else {
      
    $opt_in 0;
    }
    $sql "INSERT INTO `tablename` (`its`, `friday`) VALUES (0,{$opt_in})"
    Note that I made $opt_in to 1 in both cases, it should have been 1 if the checkbox was checked and 0 if it was not checked. Apologies for any confusion I may have caused with that code snippet.
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2
    Originally Posted by badger_fruit
    Oops, I made a mistake when I wrote the last post:-

    PHP Code:
    if (isset($_POST['checkboxname']) {
      
    $opt_in 1;
    } else {
      
    $opt_in 1;
    }
    $sql "INSERT INTO `tablename` (`its`, `friday`) VALUES (0,{$opt_in})"
    SHOULD read

    PHP Code:
    if (isset($_POST['checkboxname']) {
      
    $opt_in 1;
    } else {
      
    $opt_in 0;
    }
    $sql "INSERT INTO `tablename` (`its`, `friday`) VALUES (0,{$opt_in})"
    Note that I made $opt_in to 1 in both cases, it should have been 1 if the checkbox was checked and 0 if it was not checked. Apologies for any confusion I may have caused with that code snippet.
    no thats ok. i figured that it sould have been a zero. I was confused about the whole process but am having a go now and will post my results
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    70
    Rep Power
    2
    Originally Posted by jonnyfreak
    no thats ok. i figured that it sould have been a zero. I was confused about the whole process but am having a go now and will post my results
    my page i very large so i have tried to make a temp page to just test this but am coming up with some syntax errors

    can you have a look for me and tell me where i have gone wrong?

    PHP Code:
    <?php if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""

    if (
    PHP_VERSION 6) { 
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; }

    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch (
    $theType) { 
    case 
    "text"
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL"; break; 
    case 
    "long"
    case 
    "int"
    $theValue = ($theValue != "") ? intval($theValue) : "NULL"
    break; 
    case 
    "double"
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"
    break; 
    case 
    "date"
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL"; break; 
    case 
    "defined"
    theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue; break; 

    return 
    $theValue
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) { $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']); 

    if (isset(
    $_POST['signed']) { 
    $opt_in 1
    } else { 
    $opt_in 0;
     }
    if ((isset(
    $_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) 
    $updateSQL sprintf("UPDATE plus_signup SET signed=%s WHERE userid=%s"
    GetSQLValueString(isset($_POST['signed']) ? "true" """defined","1","0"), 
    GetSQLValueString($_POST['userid'], "text")); 

    mysql_select_db($database_hostprop$hostprop); $Result1 mysql_query($updateSQL$hostprop) or die(mysql_error()); 
    $updateGoTo "eLease.php"
    if (isset(
    $_SERVER['QUERY_STRING'])) { 
    $updateGoTo .= (strpos($updateGoTo'?')) ? "&" "?"$updateGoTo .= $_SERVER['QUERY_STRING']; 
    }
    header(sprintf("Location: %s"$updateGoTo)); 


    $colname_Recordset1 "-1"
    if (isset(
    $_GET['userid'])) { 
    $colname_Recordset1 $_GET['userid']; 

    mysql_select_db($database_hostprop$hostprop);
     
    $query_Recordset1 sprintf("SELECT userid, signed FROM plus_signup WHERE userid = %s AND plus_signup.signed = 0"GetSQLValueString($colname_Recordset1"text"));
    $Recordset1 mysql_query($query_Recordset1$hostprop) or die(mysql_error()); $row_Recordset1 mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 mysql_num_rows($Recordset1); ?>

    thanks
    Last edited by jonnyfreak; October 12th, 2012 at 07:06 AM. Reason: reformatted code
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo