Jump to content

Hardcoding a post variable


Awanka

Recommended Posts

How do send a post variable to the next form?  I don't want to do it through a checkbox, sessions, cookies, or any kind of user input field.  I just want something like

 

$_POST['thisvar'] = 'VarOne'; 

 

to send a post variable to the new form when it is submitted.

Link to comment
Share on other sites

<input type="hidden" name="thisvar" value="VarOne" />

The only problem is that *technically* this can be modified for the client.  If they happen to look through your source and create a javascript function to modify the value.  The chances of it happening?  Low...but still.  Generally speaking I think it's smarter to encrypt any hardcoded values before showing them to the client, that way if they try to edit it...there's less of a chance that they'll actually make a difference.

Link to comment
Share on other sites

Only way is with a hidden field but if you'd like better opinions you need to provide a little better example of what you're trying to do.  You talk about getting rid of a session var but that is extremely easy to do.

 

Again, provide a little better example of what you're trying to do and maybe we can help more.

 

 

 

Link to comment
Share on other sites

I have a page that has a link that produces a popup when clicked

 

<a href="javascript:void(0)" onclick="openPopup('recentCampSettingsExcel.php', 'recentCampSettingsExcel', 600, 500)"><b>(Export to Excel)</b></a>

 

It calls the following php page which has rows of checkboxes that are linked to particular values in a database

 

===================================================================

<?php
include 'includes/php_includes.php';
include 'includes/header_simple.php';

function createMetricsListHTML($metricsArray, $curMetricsSelected, $curSelectAllFlags)  {
$groupNames = array( 1=> "General", 2 => "Buyer", 3 => "Seller", 4 => "Default");
$htmlOut = "
<tr>
<td class=\"tdcellgry\" valign=\"top\" align=\"right\"><b>Metrics:</b></td>";

foreach($metricsArray as $grouping => $metricsList)  {

	$htmlOut.="
	<td class=\"tdcellwhi\" valign=\"top\">
	<table cellpadding=\"-1\" cellspacing=\"-1\" bgcolor=\"#FFFFFF\" width=\"100%\">
	<tr><td class=\"tdcellgry\" align=\"center\"><i><b>$groupNames[$grouping]</b></i></td></tr>";
	if(is_array($metricsList))  {
		foreach($metricsList as $oneMetric)  {
			$htmlOut.="
			<tr><td><input type=\"checkbox\" name=\"metrics[]\" value=\"$oneMetric[m_id]\"";
			if(in_array($oneMetric["m_id"], $curMetricsSelected)) {
				$htmlOut.=" checked";
			}
			$htmlOut.="> $oneMetric[m_dispname]</td></tr>";
		}
	}
	$htmlOut.="
		</table>
	</td>";
}

$htmlOut.="
<tr><td></td>";
foreach($groupNames as $key => $metricType)	{
	$htmlOut.= "<td><input type=\"checkbox\" name=\"checkAll${metricType}\" value=\"true\" onclick=\"submit();\"";
		if($curSelectAllFlags[$key] == TRUE)	{
			$htmlOut.= "checked > All $metricType</td>";
		}
		else	{
	$htmlOut.= " > All $metricType</td>";
	}
}
$htmlOut .= "</tr>";
return $htmlOut;
}

$dashVars = DashboardDB::getDashboardSession();

$curChannel = $dashVars['recent_camps_channel'];

$curTimeSpan = $dashVars['recent_camps_timespan'];
$curLiveFlag = $dashVars['recent_camps_liveflag'];
$curSelectAllFlags = $dashVars['select_all_flags'];
$curMetrics = $dashVars['recent_default_camps_metrics'][$dashVars['metricType']];

$metricsArray = DashboardDB::getAvailableDisplayMetrics($curChannel);

//$_REQUEST["checkAllDefault"] = true;


$groupNames = array( 1=> "General", 2 => "Buyer", 3 => "Seller", 4 => "Default");

foreach($groupNames as $key => $metricType)	{



if($curSelectAllFlags[$key] != $_REQUEST["checkAll${metricType}"])	{ //If boolean values don't match
$curSelectAllFlags[$key] = !$curSelectAllFlags[$key]; //Switch boolean value

//Process rows for metricType by new boolean value (all/none)
$curChannelMetricsArray = $curMetrics[$curChannel];

if($curSelectAllFlags[$key] == true)	{  //All boxes set to checked
	foreach($metricsArray[$key] as $oneMetric)	{
		if(!in_array($oneMetric['m_id'], $curChannelMetricsArray))	{
			//	echo "WHAT THE ".$oneMetric['m_id']."BUCK";
			$curChannelMetricsArray[] = $oneMetric['m_id'];
		}
	}
}
else 	{ //All boxes set to unchecked
foreach($metricsArray[$key] as $oneMetric)	{
	if(in_array($oneMetric['m_id'], $curChannelMetricsArray))	{
	    $removeKey = array_search($oneMetric['m_id'], $curChannelMetricsArray);
	    //				echo "WHAT THE ".$removeKey."BUCK";
	    unset($curChannelMetricsArray[$removeKey]);
	}
}
}

sort($curChannelMetricsArray);
$curMetrics[$curChannel] = $curChannelMetricsArray;
$dashVars['select_all_flags'] = $curSelectAllFlags;
$dashVars['recent_default_camps_metrics'][$dashVars['metricType']] = $curMetrics;


}

}

if(isset($_REQUEST['exportSubmit']))  {

$metrics = $_REQUEST['metrics'];

$metricsLists = $dashVars['recent_export_camps_metrics'];
//echo $dashVars['metricType'];
$metricsLists[$dashVars['metricType']][$curChannel] = $metrics;

//Saves data so DashboardDB can grab this data internally
$dashVars['recent_export_camps_metrics'] = $metricsLists;
$dashVars['channel']=$curChannel;
DashboardDB::saveDashboardSession($dashVars);

	header('location:campExport.php');
}

$metricsListHTML = createMetricsListHTML($metricsArray, $curMetrics[$curChannel], $curSelectAllFlags);
DashboardDB::saveDashboardSession($dashVars);
?>

<form name="recentCampSettings" action="#" method="post">
<input type="hidden" name="channel" value="<?php echo $curChannel?>">

<body "javascript:void(0)" onSubmit=<?php $dashVars['submit'] = 'T'; DashboardDB::saveDashboardSession($dashVars)?>>

<table cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td class="tblhdrpri"  colspan=5><b>Select Fields to Export</b></td>
</tr>
<!--<tr>
<td class="tdcellgry" align="right"><b>Include Live:</b></td><td class="tdcellwhi" colspan=4><input type="checkbox" name="livecheck" <?php if($curLiveFlag) {echo "checked";}?>></td>
</tr>-->
<?php echo $metricsListHTML?>

<tr cellpadding="1" cellspacing="1">
	<td class="tdcellwhi" align="center" colspan=5><input type="submit" name="exportSubmit" value="Export Submit"></td>
</tr>

</table>
</body>
</form>
<?php
include 'includes/footer_simple.php';
?>

=========================================

 

There are checkboxes at the bottom row that select all the values for the column that they belong to.  I want one of the check all in column checkboxes to start out checked when the popup is opened though.  For this to work, the popup needs to know the first time it was opened.  Someone previously suggested using a session variable.  This is great, except that I have to unset it when the popup is closed, and I can't do that without breaking the checkbox feature.  I can do it using an onunload event handler, but the submit() function in the

 

$htmlOut.= "<td><input type=\"checkbox\" name=\"checkAll${metricType}\" value=\"true\" onclick=\"submit();\"";

 

line also triggers it every time the user clicks on a select all in column checkbox.

Link to comment
Share on other sites

I'm confused... Just because you are displaying a popup, why would you not have access to the php session var?  You wouldn't have to clear it on the close event, you can destroy the session var on the load of the popup.  On first line of file after session start of course, does var exist?  yes, check box, clear var, now show popup...

 

From that point on the var has been turned off.  It would only get turned on if the user did whatever it is you want them to do that would reset it back to true...

 

 

 

Link to comment
Share on other sites

The problem I have with the session is getting rid of the variable.  I'd have to know the first time the popup window was opened, and I'm finding that to be a lot more difficult than it seems.

 

Getting rid of the session variable is easy... in the pop-up window just put unset($_SESSION['thisvar'] in the pop-up page (after you use it!).

 

You don't need to check if the page has opened - you'll know it has by the fact the line has run.

Link to comment
Share on other sites

I'm confused... Just because you are displaying a popup, why would you not have access to the php session var?  You wouldn't have to clear it on the close event, you can destroy the session var on the load of the popup.  On first line of file after session start of course, does var exist?  yes, check box, clear var, now show popup...

 

From that point on the var has been turned off.  It would only get turned on if the user did whatever it is you want them to do that would reset it back to true...

 

Well, that's the problem.  I would have to reset it on the close event or the open event of the popup.  I'm finding doing it on the close event is difficult, so I'm going to try to embed it into the line that opens the popup:

 

<a href="javascript:void(0)" onclick="openPopup('recentCampSettingsExcel.php', 'recentCampSettingsExcel', 600, 500)">(Export to Excel)[/url]

 

Any suggestions would be appreciated.

Link to comment
Share on other sites

It worked.  Thanks guys.

 

 

<a href="javascript:void(0)" onclick="<?php session_start();$_SESSION['firstTime'] = 'T';session_write_close();?>openPopup('recentCampSettingsExcel.php', 'recentCampSettingsExcel', 600, 500)"><b>(Export to Excel)</b></a>

Link to comment
Share on other sites

The onclick action event handler is javascript

 

No kidding? Hence, it runs on the client, while the php your trying to envoke with it runs on the server. Now you see my point?

 

You try and call server side php functions (session_start() & session_write_close()) from javascript on the client.

Link to comment
Share on other sites

Let me try to elaborate on what thorpe is trying to say here.

 

Say you have a page that sets session foo to value bar:

<?php
$_SESSION['foo'] = 'bar';
?>

Later on in the page, you want to print a link to a popup that requires the data from that session, so your popup window script looks something like this

<?php
if ($_SESSION['foo'] == 'bar')
{
     // Run the code for that condition here (this script is in your popup window
}
elseif ($_SESSION['foo'] == 'foobar')
{
     // Some other code in case session foo == foobar
}

// By this point in the script, you're done with the session variable...
unset($_SESSION['foo']);
?>

Done.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.