Jump to content

Keeping Vars through multiple submits


strategos

Recommended Posts

Hello, I am having an issue where PHP nulls the donation amount after multiple form submits. Here is a synopsis of what is happening.

 

1: User enters donation amount and clicks 'submit'

2: Is taken to a confirmation page where they must agree to terms

3: User fails to agree to the terms, the page is reloaded with an error message, and the donation amount is set to null

 

I want to make the donation amount display despite multiple confirm page reloads. How would I do this?

 

Here is the site to test it yourself. Ignore the steamid input and check "do not change my rank upon donation" to test.

 

http://forums.stgdarkrp.org/donate2/check.php

 

Please note: If you use IE, the formatting is messed up, that is a problem I will look into later

Link to comment
https://forums.phpfreaks.com/topic/260475-keeping-vars-through-multiple-submits/
Share on other sites

I have tried using a session var, but the result is the same.

 

Here is the code (I know its inefficient; its my first script)

 

<?php

session_start();

$amount = $_POST['amount'];

$cents = $_POST['coins'];

$agree = $_POST['confcheck'];

// Steam Donation System by Strategos

if (isset($_COOKIE['FormSubmitted']) && !isset($_POST['confirm'])){
die('
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="english" id="vbulletin_html">
  <head>
    <title>Donation Title</title>

<link rel="stylesheet" href="css/structure.css" type="text/css" />
<link rel="stylesheet" href="css/form.css" type="text/css" />
<link rel="stylesheet" href="css/button.css" type="text/css" /> 

<!--[if lt IE 10]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
  </head>
<body style="margin-top:20%; margin-bottom:20%;">
    
    
<div id="container" class="ltr">

<h1 id="logo">
STG
</h1><br><center><h3>You just submitted a form. Please wait 5 seconds before trying again.</h3></center>



<center><a href="check.php">Try Again</a></center><br>
</div><!--container-->

    
    
  
</body>
</html>');
}

// Checks if qualifies for benefits

if($total >= 5){
$donator_qual = true;
}


//*

// Begin Processing

$inputid = $_POST['steamid'];

$steam_prefix = substr($inputid, 0, 10);

$prefix_length = 10;

$char_total = strlen($inputid);

$amount_chars = strlen($amount);

$steam_suffixchars = ($char_total - $prefix_length);

$suffix_check = substr($inputid, 10, $steam_suffixchars);

$class_set = "notranslate";

$class_set2 = "notranslate";

$error_set = "hidden";

$coin_chars = strlen($cents);

$errordiv_p = "";

if(is_numeric($suffix_check) == true)
$suffix_valid = true;
elseif(is_int($suffix_check) == false)
$suffix_valid = false;

if($char_total > 25 || $char_total < 11)
$char_valid = false;
else
$char_valid = true;


if($steam_prefix === "STEAM_0:1:" || $steam_prefix === "STEAM_0:0:")
$prefix_check = true;
elseif($steam_prefix != "STEAM_0:1:" || $steam_prefix != "STEAM_0:0:")
$prefix_check = false;

if (preg_match('/^[A-Z0-9-:]+$/', $inputid))
$chars_matched = true;
else
$chars_matched = false;

$inputid = $_POST['steamid'];

if (preg_match('/^[0-9-]+$/', $cents) && $cents >= 0 && $cents <= 99 && $coin_chars == 2)
$coin_check = true;
else
$coin_check = false;

if (preg_match('/^[0-9-]+$/', $amount) && $amount >= 0)
$amount_check = true;
else
$amount_check = false;

if ($amount == 0 && $cents == 0)
$iszero = true;
else
$iszero = false;

if (isset($_POST['submit'])) {

if($suffix_check == true && $prefix_check == true && $char_valid == true && $chars_matched == true && $amount_check == true && $coin_check == true && $iszero == false){
$part1 = true;
}
elseif(isset($_POST['anon'])){
$part2 = true;
$inputid = "";
}
elseif($suffix_check == false || $prefix_check == false || $char_valid == false || $chars_matched == false){
$class_set = "notranslate error";
$errordiv_p = '<p style="text-align: center; background: #FFDFDF !important; padding-top: 4px; color:red; border-style:solid; border-width:1px; padding-bottom: 7px;">
<b>Error:</b> There is an error with the highlighted field(s)</p>';
$error_set = "";
}
if($amount_check == false || $coin_check == false || $iszero == true){
$class_set2 = "notranslate error";
$errordiv_p = '<p style="text-align: center; background: #FFDFDF !important; padding-top: 4px; color:red; border-style:solid; border-width:1px; padding-bottom: 7px;">
<b>Error:</b> There is an error with the highlighted field(s)</p>';
$error_set = "";
}

}

if($part1 == true || $part2 == true && $amount_check == true && $coin_check == true && $iszero == false || isset($_POST['confirm'])){

setcookie('FormSubmitted', '1', time()+10);

// STEAM ID CONVERSION

$X = substr($inputid, 6, 1);

$Y = substr($inputid, 8, 1);

$c_id = (($suffix_check * 2) + $X + $Y + 76561197960265728);

//*

// RANK DONATION

if($inputid != ""){
$steamid_div = '<div id="radio" name="hide">
<li id="foli111" class="notranslate">
<label class="desc" id="title111" for="Field111">
SteamID: <br /> 
<p style="font-family: verdana; color:green; font-weight: bold;">'.$inputid.'</p>
</label>
<div>
<p style="font-family: verdana; color:green; font-weight: bold;"></p>
</div>
</li>
</div>';
}
elseif($inputid == "")
$steamid_div = "";

//*

$total = "$amount.$cents";

// CONFIRMATION TEMPLATE

$conf_page = '<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>Confirm</title>

<link rel="stylesheet" href="css/structure.css" type="text/css" />
<link rel="stylesheet" href="css/form.css" type="text/css" />

<script src="scripts/hide.js"></script>
<script src="scripts/submitcl.js"></script>

<!--[if lt IE 10]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
  </head>
  <body>
     
    
    </label>
<div id="container" class="ltr">

<h1 id="logo">
STG
</h1>

<form onSubmit="return clearForm(MyForm)" id="MyForm" name="conf_form" class="wufoo topLabel page" autocomplete="off" enctype="multipart/form-data" method="post" novalidate
action="check.php">

<header id="header" class="info">
<h2>Confirm Information</h2>
<div></div>
</header>

<div style="visibility: ;" id="errorset" name="errorset">

'.$conf_error.'

</div>

<br />

<ul>

'.$steamid_div.'

<li id="foli0" class="notranslate">
<label class="desc" id="title0" for="Field0">
Donation Amount:
</label>
<span>
<p style="font-family: verdana; color:green; font-weight: bold;">$ '.$total.'</p>
</span>
</li>
<li id="foli10" class="notranslate      ">
<fieldset>
<![if !IE | (gte IE ]>
<legend id="title10" class="desc">
</legend>
<![endif]>
<!--[if lt IE 8]>
<label id="title10" class="desc">
</label>
<![endif]-->
<div>
<span>
<input id="check" name="confcheck" type="checkbox" onclick="" value="agree" tabindex="7" />
<label class="choice" for="Field10">I agree to the terms and conditions.</label>
</span>
</div>
</fieldset>
</li> <li class="buttons ">
<div>
<input id="saveForm" name="confirm" class="btTxt submit" type="submit" value="Submit"
/></div>
</li>

</ul>
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
</form> 
<p style="font-size: 10px; text-align: center;">By donating, you agree to the terms and conditions found <a style="font-size: 10px; text-align: center;" href="http://forums.stgdarkrp.org/showthread.php?619-Donation-Rules&p=3712#post3712" >here</a></p>
<br />
</div><!--container-->
  </body>
</html>';
//* END CONFIRMATION TEMPLATE

// Accept terms check

if($agree == NULL && isset($_POST['confirm'])){
$conf_error = '<p style="text-align: center; background: #FFDFDF !important; padding-top: 4px; color:red; border-style:solid; border-width:1px; padding-bottom: 7px;">
<b> You must agree to the terms and conditions.</b></p>';
}

elseif($agree == "agree" && isset($_POST['confirm'])){
$conf_error = "";
session_destroy();
header("Location: http://www.google.com");
}

var_dump($total, $amount);

//*

echo $donator_qual;

echo $conf_page;

echo '<a href="http://steamcommunity.com/profiles/'.$c_id.'" target="_blank">
<img src="http://badges.steamstatus.com/profile/default/steam/'.$c_id.'.png" />
</a>';

}
elseif (!isset($_COOKIE['FormSubmitted']))
echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="english" id="vbulletin_html">
  <head>
    <title>Donation Title</title>

<link rel="stylesheet" href="css/structure.css" type="text/css" />
<link rel="stylesheet" href="css/form.css" type="text/css" />
<link rel="stylesheet" href="css/button.css" type="text/css" /> 

<script src="scripts/hide.js"></script>
<script src="scripts/submitcl.js"></script>

<!--[if lt IE 10]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
  </head>
  <body>
    
    </label>
<div id="container" class="ltr">

<h1 id="logo">
STG
</h1>

<form onSubmit="return clearForm(MyForm)" id="MyForm" name="MyForm" class="wufoo topLabel page" autocomplete="off" enctype="multipart/form-data" method="post" novalidate
action="check.php">

<fieldset class="form">

<header id="header" class="info">
<h2>Donation Form</h2>
<div></div>
</header>

<div style="visibility: notranslate error;" id="errorset" name="errorset">

'.$errordiv_p.'

</div>

<br />

<ul>

<div  id="radio" name="hide">
<li id="foli111" class="'.$class_set.'">
<label class="desc" id="title111" for="Field111">
Please enter your SteamID here or check the box below.
</label>
<div>
<input placeholder="STEAM_0:X:XXXXXX" id="steamid" name="steamid" type="text" class="field text medium" value="" maxlength="30" tabindex="3" onkeyup="" />
</div>
</li>
</div>
<li id="foli0" class="'.$class_set2.'">
<label class="desc" id="title0" for="Field0">
Donation Amount
<span id="req_0" class="req">Must be $5 or greater for benefits </span><a target="_blank" href="http://forums.stgdarkrp.org/showthread.php?619-Donation-Rules&p=3712#post3712"><img src="images/question.png" alt="Help" /></a>
</label>
<span class="symbol">$</span>
<span>
<input placeholder="5" id="Field0" name="amount" type="text" class="field text currency nospin" value="" size="4" tabindex="4" required />
<label for="Field0">Dollars</label>
</span>
<span class="symbol radix">.</span>
<span class="cents">
<input placeholder="99" id="Field0-1" name="coins" type="text" class="field text nospin" value="" size="2" maxlength="2" tabindex="5" onkeyup="handleInput(this);" onchange="handleInput(this);">
<label for="Field0-1">Cents</label>
</span>
<li id="foli10" class="notranslate      ">
<fieldset>
<![if !IE | (gte IE ]>
<legend id="title10" class="desc">
</legend>
<![endif]>
<!--[if lt IE 8]>
<label id="title10" class="desc">
</label>
<![endif]-->
<div>
<span>
<input id="check" name="anon" type="checkbox" onclick="toggleAlert()" class="field checkbox" value="" tabindex="7" />
<label class="choice" for="Field10">Do not change my rank upon donation <a target="_blank" href="http://forums.stgdarkrp.org/showthread.php?619-Donation-Rules&p=3712#post3712"><img src="images/question.png" alt="Help" /></a></label>
</span>
</div>
</fieldset>
</li> <li class="buttons">
<div>
<button type="submit" id="button" class="positive" name="submit">
<img src="images/money.png" alt="Announcement">Donate</button>
</div>
</li>
</ul>
</fieldset>
</form> 
<p style="font-size: 10px; text-align: center;">By donating, you agree to the terms and conditions found <a style="font-size: 10px; text-align: center;" href="http://forums.stgdarkrp.org/showthread.php?619-Donation-Rules&p=3712#post3712" >here</a></p>
<br />
</div><!--container-->
  </body>
</html>';
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.