Jump to content

I think I build a loop in my submit form, but where?


Luis
 Share

Recommended Posts

Hey,

while trying to build a user edit thingy I ran into a problem, which is confusing me.
The form got 3 text inputs and 2 checkboxes, if I dont touch the checkboxes and just edit the text fields everything works fine.

If I try to mark a box as checked, it looks like the script is running into a loop and finally throws an 500 Internal.
As you can see the save() function is at the very bottom of the script and the script reaches this point as it saves the checkboxes just fine. 

I dont get it. 

Maybe someone could help.

  //check if the user edit form is submitted
  if($input->post->submit)
  {
    //set the outputformat to false in preparation to edit some changes
    //check if mail or pass will be changed, if not we dont need OF() false on $user
    if($input->post->clientpass || $input->post->clientemail)
    {
      $client->of(false);  
    }
    $clientFolder->of(false);
    
    //BEGIN OF PASSWORD EDIT -- First check if trying to edit the user pass
    if($input->post->clientpass)
    {
      //check if both, clientpass and clientconfirmpass matches
      if($input->post->clientpass == $input->post->clientpassconfirm)
      {
        //populate the tmp_pass instead of the pass field, in case the user reminds his password        
        $client->tmp_pass = $input->post->clientpass;  
        $successPass = 1;  
      }
      //passwords dont match, throw an error.
      else
      {
        $error = 1;
        $errorPass = 1;
      } 
    
    }
    //END OF PASSWORD EDIT
    
    //BEGIN E-MAIL EDIT -- First check if trying to edit the user mail
    if($input->post->clientemail)
    {
      $clientmail = $sanitizer->email($input->post->clientemail);
      //if sanitation fails the VAR is empty and we throw an error else save the mail
      if(!$clientmail)
      {
        $error = 1; 
        $errorMail = 1;        
      }
      //no errors and so we change Users mail
      else
      {
        $client->email = $clientmail;
        $successMail = 1;  
      }
    } 
    // END OF E-MAIL EDIT
    
    // BEGIN OF CHECKBOX EDIT -- We start with activating the clients subscription
    if($input->post->clientabo && !$clientFolder->SettingsIsPremium)
    {
        $clientFolder->SettingsIsPremium = 1;
        $success = 1;
        $successAbo = 1;        
    }
    //now we check if we wanna activate the Users Dashboard
    if($input->post->clientactive && !$clientFolder->SettingsIsConfirmed)
    {      
        $clientFolder->SettingsIsConfirmed = 1;
        $success = 1;
        $successActive = 1;        
    }    
    //if our checkboxes are empty we uncheck them in database
    if(!$input->post->clientabo && $clientFolder->SettingsIsPremium)
    {
        $clientFolder->SettingsIsPremium = 0;
        $success = 1;
        $successUnsubscribe = 1;        
    }
    //now we check if we wanna deactivate the User
    if(!$input->post->clientactive && $clientFolder->SettingsIsConfirmed)
    {     
        $clientFolder->SettingsIsConfirmed = 0;  
        $success = 1;
        $successDeactive = 1;        
    }  
    // END OF CHECKBOX EDIT 
    
    //now check which fields got changes and save the changes. 
    //first we check if mail or pass got changes, if so we save the $user and set OF to false after saving
    if($successMail == 1 || $successPass == 1)
      {
        $client->save();
        $client->of(true);  
      }
    //now we check if our checkboxes got changes and doing the same
    if($success == 1)
    {
      $clientFolder->save(); 
    }    
    $clientFolder->of(true); 
  }//<-- /if submit

Link to comment
Share on other sites

<?php 

//if our GET VAR is empty show the clients overview
if(!$input->get->edituser)
{
  include('./includes-backend/admin/scripts/clientsOverview.php');   
}

//check if our GET VAR is populated
if($input->get->edituser)
{
  //check if our GET VAR is an existing User, if so we show the User Profile else show the overview
  $client = $users->get($input->get->edituser);  
  if($client->id)
  {
    //fine, the submited id is an existing user, now grab the related user folder as Page Field Relation    
    $clientData = $client->ClientUserRelation;    
         
    $clientFolder = $pages->get($client->ClientUserRelation->id);
      
    //include the user profile with edit form     
    include('./includes-backend/admin/scripts/clientsEdit.php');
  }
  //submitted ID is not an existing user, so we show the overview
  else
  {
    include('./includes-backend/admin/scripts/clientsOverview.php'); 
  }
}

?>

snippet is included in clientsEdit

dont be confused of $clientFolder, was a test if the page relation maybe caused the trouble, which dont

Link to comment
Share on other sites

Hm,

I added some more fields to look which save action is the problem. 

the $user->save() works fine, no problems. 

In case I edit any field of the corresponding page, related to the $user, the apache throws a 500 Internal but after looking into the edited page, every change has been saved properly.

Strange

EDIT:

it works now, i dropped the $page->save() at bottom and save every field by his particular name in his own if statement like this

if($input->post->clientactive && !$clientFolder->SettingsIsConfirmed)
    {      
        $clientFolder->SettingsIsConfirmed = 1;
        $clientFolder->save("SettingsIsConfirmed");
        $success = 1;
        $successActive = 1;        
    }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...