Jump to content

Need a variable to appear only first time form is called


Awanka

Recommended Posts

I have a problem where I need a $_REQUEST variable to appear the first time I call a page, but need it to disappear for each successive "submit()" of that page.

 

The line that calls the page is:

 

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

 

I need that $_REQUEST variable to be defined when the php page is first show.  But the page has a submit() feature.  And each time that submit feature is pressed I need the original $_REQUEST to disappear.  But I can't get it to go away, like it's hardcoded to the php form.  I've tried unset() and reassigning it.  It just resets to its original value each time.

 

I've thought of maybe assigning it in the called page, but I can't figure out a way to get it to be defined only the first time it's called there either.

 

I would appreciate any help.

 

Link to comment
Share on other sites

 

I don't want to post the whole thing.  It's just too big.

 

My problem is that I need a variable to be defined the ONLY the first time a form is called.

ie.

$checkAllDefault=true;

 

The form has a submit() function tied to a checkbox:

 

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

 

And when the user clicks on that checkbox and the form reloads, I need the variable

$checkAllDefault=true;

to not be defined, because it's tied to one of the other checkboxes and it won't do what I want it to if it's hardcoded.

 

It seems like a simple problem, but I can't figure a way around it.  I thought I could use a counter but those get reset every time the page is loaded too.  How do I know the first time a page is called?

Link to comment
Share on other sites

 

That doesn't work because sometimes the $_POST['checkboxname'] variable isn't set after the form is submitted.  It's only set if the checkbox has been clicked on.

 

Isn't there some way to tell the first time a form is opened by a user?  I'd settle for an inelegant solution.  Something like

 

 

$count=0;

 

<form is submitted>

$count++;

 

That doesn't work though because the $count=0 part get re-executed every time.

Link to comment
Share on other sites

I'm confused about where I should reset the counter to 0.  Can I embed that into the call to the php page?

 

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

 

 

Is there a way for me to stick a $_SESSION['counter']=0 within that line of code?

 

I can't set the session variable to 0 within the 'recentCampSettingsExcel.php' page itself.  Or it will get called every time.

 

Otherwise I don't see a way to do it using session variables.

 

I'm finding it faintly ridiculous that there isn't a simpler way to tell the first time a page is called.  I think this would be an important piece of information that is used often.

Link to comment
Share on other sites

I'm finding it faintly ridiculous that there isn't a simpler way to tell the first time a page is called.  I think this would be an important piece of information that is used often.

 

Maybe so, but http is stateless. Nothing to do with php.

 

A simple example oif using sessions.

 

<?php

  session_start();

  // if first load.
  if (!isset($_SESSION['firsttime'])) {
    $_SESSION['firsttime'] = true;
  } else {
    // must have been here before.
    $_SESSION['firsttime'] = false;
  }

  // now to your variable.
  if ($_SESSION['firsttime'])) {
    $checkAllDefault = true;
  }

?>
    

Link to comment
Share on other sites

I have an additional problem now.  I need the session variable to be cleared when the popup window that created it closes.  I can't use the javascript onunload even handler though because some of my checkboxes in the popup use the submit() function, and I can't have the session variable clearing every time someone clicks on a checkbox.  I only want to clear it once the actual popup is closed.

 

Here is the relevant code:

 

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

<form name="recentCampSettings" action="#" method="post">

<input type="hidden" name="channel" value="<?php echo $curChannel?>">

 

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

<table cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">

<tr>

<td class="tblhdrpri"  colspan=5>Select Fields to Export</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>

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

 

Here is the code for the checkbox that submits the form and also triggers the onUnload event handler against my wishes

 

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

 

Any help would be appreciated

 

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.