Jump to content

Beginner ?: What is this php code doing inside this form?


erinod

Recommended Posts

Hi all,

I am trying to replicate/modify this checkbox for a different script and I don't understand what the php code is doing in this form? Could someone explain to me whats happening by including that php code in the form?

 

<input type="checkbox" onclick="showArchive()" NAME="showarchive" id="showarchive" <?php echo ($showarchive ? 'checked="checked"' : '');?> />

 

Thanks!

 

So would this piece of code cause the checkbox to remain checked on page reloads? Is it possible that the user checks the box once, thereby creating the $showarchive variable, and that this piece of code then keeps the checkbox selected during the rest of their session? I also am trying to figure out how these pieces of scripts are interacting with one another:

 

Here's the form:

<FORM ACTION="?m=quotes" METHOD="post" NAME="quoteForm" ID="quoteForm">
    <B> Show Archived: </B><input type="checkbox" onclick="showArchive()" NAME="showarchive" id="showarchive" <?php echo ($showarchive ? 'checked="checked"' : '');?> />

 

And this seems to be where $showarchive is defined:

 

if (isset( $_GET['showarchive'] )) {
    if($_GET['showarchive']  == "noshow"){
       $showarchive = '';
       $show = "noshow";
       $AppUI->setState( 'QuoteIdxCond', 'noshow');
    }
    else{
       $showarchive = "show";
       $show = "show";
       $AppUI->setState( 'QuoteIdxCond', 'show');
    }
}
$show = $AppUI->getState( 'QuoteIdxCond' ) ? $AppUI->getState( 'QuoteIdxCond' ) : '';
if($show == "show")
  $showarchive = "show";
else
  $showarchive = '';

 

Even though the form uses post, can this script use $_GET to call the data from the form? That is my understanding of what is happening, but I wasn't sure you could do that or why it was written this way.

 

Then the same script that holds the form also has a Javascript function that is called to with onClick:

function showArchive() {

     f = document.quoteForm.showarchive.checked;
    if(f == true)
       window.location =('./index.php?m=quotes&showarchive=show');
    else
      // window.location =('./index.php?m=quotes&showarchive=noshow');
      window.location =('./index.php?m=quotes&showarchive=noshow');
      
}

What I don't understand here is how the url's are defined. I'm trying to copy this whole process to have a checkbox like this one on a different page which filters a search so I'm just trying to understand how this works.

 

Thanks for any further help

 

 

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.