CodeIgniter Forums

Full Version: Java Popup Window ain't working in php code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jonnyG[/eluser]
hey there,
I'm just writing a little formular, if something is not completly filled out there should show up a little java alert window...

Controller
Code:
$this->form_validation->set_rules('name', 'Name', 'required');


  if ($this->form_validation->run() == FALSE)
  {
   $alert['bool'] = true;
   $alert['message'] = "ooops something missing!";
   print_r($alert);
   $this->load->view('header');
   $this->load->view('pages/req', $alert);
   $this->load->view('footer');
  }
  else
  {
   $alert['bool'] = true;
   $alert['message'] = "Your request was send!";

   $this->load->view('header');
   $this->load->view('req', $alert);
   $this->load->view('footer');
  }

View
Code:
<?php
if($bool == true){?>
[removed]
function myFunction()
{
alert(<?=$message?>);
}
[removed]

<?php  
}
?>

print_r($alert); --> Array ( [bool] => 1 [message] => ooops something missing! )

any idea where the problem could be?
the [removed] stands for javascript....

El Forum

[eluser]InsiteFX[/eluser]
Maybe php short open tags are turned off.
Code:
alert(<?php echo $message;?>);

El Forum

[eluser]jonnyG[/eluser]
no thats not the problem.. using it nearly everywhere where using variables

El Forum

[eluser]InsiteFX[/eluser]
To display the message you have to be calling the myFunction someplace but I do not see you calling.

Maybe your not showing all the code.

El Forum

[eluser]guzzilar[/eluser]
in js code try

Code:
var msg = <?=$message;?>;

function test(msg)
{
     alert(msg);
}

try this :)

El Forum

[eluser]jonnyG[/eluser]
ah okay! I change it to

Code:
<?php
if($bool == true){
echo myFunction();
}
?>

function
Code:
[removed]
function myFunction()
{
alert(<?php echo $message; ?>);
}
[removed]

but now I just get a blank page with the output from the array.. ??

El Forum

[eluser]jonnyG[/eluser]
Code:
<?php
if($bool == true){
echo do_alert($message);
}
?>

<?php
function do_alert($message)
    {
        echo '[removed]alert("' . $message . '"); [removed]';
    }
?>


solved it this way now..
but if the popup shows up some areas in the back are missing(looks weird)