Jump to content

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


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

 

 

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.