one form button two function

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

one form button two function

Post by jonnyfortis »

I have a form with a checkbox and an image button. If the tick 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 to be sent the the DB (mySQL),

this is what i have currently
<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><br />
<input type="image" src="../images/smalldownload.png" width="35" height="35" alt="download" value="submit"/>
</a>
<input type="checkbox" name="leaseshedule" id="leaseshedule" />
<br />
</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><br /></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 in advance
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: one form button two function

Post by requinix »

jonnyfortis wrote:thanks in advance
For what?

Spoiler: you'll have to modify eLease.php, not the stuff you posted.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: one form button two function

Post by jonnyfortis »

For what?
any advise that anyone can offer.

Why would i have to modify elease?

i thought it might be an else if statement

if not though any other help you could offer would greatly help
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: one form button two function

Post by requinix »

jonnyfortis wrote:i thought it might be an else if statement
Not really but that's besides the point. Where would you put this if/else block? Can't go in HTML and you can't put stuff in the database from JavaScript. You'd have to put it in a PHP script, and since the form points to eLease.php that's where it would go.
The checkbox is $_POST["leaseschedule"] and the "information" you speak of is... I don't know, it's not in the form. In eLease.php you check if isset($_POST["leaseschedule"]) and if so then you update your database. Otherwise, since the checkbox deals with accepting an agreement and ToC you'd probably redisplay the form with a message to the user that they need to accept everything before continuing.
jonnyfortis
Forum Contributor
Posts: 462
Joined: Tue Jan 10, 2012 6:05 am

Re: one form button two function

Post by jonnyfortis »

i have done it another way. and works fine.

Code: Select all

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form6")) {
  $updateSQL = sprintf("UPDATE signup SET signedElease=%s WHERE userid=%s",
                       GetSQLValueString(isset($_POST['signedElease']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['userid'], "text"));

  mysql_select_db($database_host, $host);
  $Result1 = mysql_query($updateSQL, $host) or die(mysql_error());

  $updateGoTo = "elease.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
with the form like this

<form action="<?php echo $editFormAction; ?>" method="post" name="form3" target="_new" id="form3">
<div align="right"><span id="sprycheckbox1">
<span class="body-text">E-Lease</span><br />
<input type="image" src="../images/smalldownload.png" width="35" height="35" alt="download" value="submit"/>
</a>
<input type="checkbox" name="SignedLeaseShed" id="leaseshedule" <?php if (!(strcmp(htmlentities($row_Recordset1['SignedLeaseShed'], ENT_COMPAT, 'utf-8'),"1"))) {echo "checked=\"checked\"";} ?> />
<br />
</span></div>
<input type="hidden" name="MM_update" value="form3" />
<input type="hidden" name="userid" value="<?php echo $row_Recordset1['userid']; ?>" />
</form><div id="ErrorZone"><span class="checkboxRequiredMsg">
error message
</span></div>
<script type="text/javascript">
var sprycheckbox1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1", {additionalError: 'ErrorZone'});
</script>

thanks for you help
Post Reply