views:

75

answers:

3

Hello there! can somebody help me with this if statement? My form appears every-time I load the page but it disappears after I submit the form! Maybe it's the "endif" syntax that confuses me but I can't get this done properly... here is the code:

<?php
if ($this->input->post('submit') && $this->input->post('categories')):
  foreach($tagedImages as $image):
  ?>
    <div class="thumb">
      <?php  echo'<a href="/toKoritsi/uploads/'.$image.'"/> <img src="/toKoritsi/uploads/thumbs/'.$image.'"/></a>' ?>
    </div>
  <?php
  endforeach;
elseif(isset($photosQuery) && count($photosQuery)):
  foreach($photosQuery->result_array() as $photo):
  ?>
    <div class="thumb">
      <?php echo'<a href="/toKoritsi/uploads/'.$photo['name'].'"/> <img src="/toKoritsi/uploads/thumbs/'.$photo['name'].'"/></a>' ?>
    </div>
  <?php
   endforeach;
endif;

$options = array(
  'bracelet'  => 'Bracelets',
  'ring'      => 'Rings',
  'bag'       => 'Bags',
  'earing'    => 'Earings'
);

echo form_open("toKoritsi/gallery");
echo form_dropdown('categories', $options, 'bracelet');
echo form_submit('submit', 'Choose');
echo form_close();
?>

thanks in advance!

A: 

Should foreach($tagedImages as $image) be foreach($taggedImages as $image)?

The formatting of your code is very ugly. If you are intent on getting nicely-formatted HTML output, perhaps you should consider using Tidy, or a template engine that offers that functionality.

Hammerite
thanks for the tip...but the problem is that the form is not displayed, all foreach loops are working fine
rabidmachine9
A: 

You definitely need to format your code properly.

I'd also recommend trying to consolidate your PHP into blocks, and keep it separate from your HTML.

You can do all the conditionals and echos WITHIN some of those HTML elements:

<div>
<?php /*...*/ ?>
</div>

as opposed to what you're doing now:

<?php /*...*/ ?>
<div>
<?php /*...*/ ?>
</div>
<?php /*...*/ ?>

In addition, things like these blocks make no sense:

    <?php endforeach;?>
            <?php endif;?>

Even if you had to break your code into small chunks, wouldn't it be easier to say:

<?php
    endforeach;
    endif;
?>

EDIT: This answer was provided before the question source was reformatted and cleaned up. I was unable to even address the original issue until I could better see what was going on.

This might sound kind of dumb, but are you sure that your gallery controller is behaving correctly? If you're submitting and there's an error in one of your CodeIgniter functions, it could be messing up the rendering after the submit.

Trafalmadorian
thanks for the tips!
rabidmachine9
@Trafalmadorian, although you are right, it really doesn´t answer the question at all.
jeroen
That's fair, but I think when I answered this the code was such a mess that even trying to decipher the source was an issue. Now at least we can see where the CodeIgniter allusions and braces are...
Trafalmadorian
A: 

I don´t know what the url structure of your site looks like, but are you sure you are submitting the form to the right place?

According to the CI user guide, it gets submitted to something like /index.php/toKoritsi/gallery but that depends on your config preferences.

jeroen
yes the form is submitted to the right place because it does what it is supposed to do...but it doesn't get displayed after I submit it!
rabidmachine9
Do you have error messaging on? Perhaps the script is coming to a stop somewhere before the form gets displayed. I would check the server log and turn on all error messages.
jeroen
It could be a good guess...I have never disabled any error messages though...
rabidmachine9