Current location: Hot Scripts Forums » General Web Coding » JavaScript » Echo image not is url


Echo image not is url

Reply
  #1 (permalink)  
Old 06-26-06, 08:27 PM
losse losse is offline
Newbie Coder
 
Join Date: Jun 2006
Location: Barrie, Ontario, Canada
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Talking Echo image not is url

Hi there
I have a 4 page registration form. On pages 1-3 I pass user inputs to a $_SESSION variable up until the last page where I use the $_SESSION to ECHO the inputs so that the user can confirm them (and go back if they made a mistake).

On page 2 of the registration form (call it form1.php) there is a field that asks the user to click on a link that opens a new window (call it form2.php) for them to select an image. For example, click here to select your image. Once they select that image, they click "next" and the window closes for them to be back on form1.php to fill out the rest of the form...

So, here's the condensed code for form1.php
PHP Code:

<?php 

session_start
(); 
if(isset(
$_POST['submit'])) 


    
$_SESSION['image'] = $_POST['image'];  

// redirect 
    
header("Location: http://www.url.php"); 

else 

?>

<form action="<?=$_SERVER['PHP_SELF']?>" name="form1" method="post"> 

<a href="#" target="new" onClick='window.open("form2.php","","width=600,height=500,resizable=no,scrollbars=no"); return false;'>Click here to select secret image</a>

<input type="hidden" name="image" value="<? if (isset($_SESSION['image'])) echo $_SESSION['image'];?>">
Now this is the code for the pop up form2.php

PHP Code:

<?php 

session_start
(); 
?>
<script type="text/javascript"> 
<!-- 

function sendFormData(form_object) 

    remoteForm = opener.document.form1; 
    remoteForm.image.value = form_object.image.value; 
    window.close(); 


--> 
</script> 

<form name="form2"> 
<p>Choose an image:</p>    
<p><input type="radio" name="image" value="image1.jpg"> File Name #1  
<p><input type="radio" name="image" value="image2.jpg"> File Name #2 

<input type="button" value="Choose file and return to main form" onClick="sendFormData(window.document.form2);"> 

</form>
Ok... now here's the problem, The entire process works well... The user can click the link, the pop up appear,s they select an image, they close the window and continue on the form...

On page 4 - the confirmation page - all the other fiels turn out fine but for some reason, the image thumbnail doesn't appear... It actually shows a broken image and when I right-click / properties, it shows:

http://www.url.com/images/undefined

Here's the code on page 4

PHP Code:

<?php 

ob_start
(); // Send the output.  
session_start(); 

<?
php 
if (!isset($_POST['submit'])) { 
// form not submitted 
?> 
<form action="<?=$_SERVER['PHP_SELF']?>" method="post"> 
?> 

<?php echo "<img src='images/" $_SESSION['image'] . "'>" ?>
Can anyone help? What I would like to do is bring out the image there, not the image path or, of course, a broken image link!
Reply With Quote
  #2 (permalink)  
Old 06-27-06, 02:25 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
It's an error in your Javascript. This should do the trick

Code:
<script type="text/javascript"> 
<!-- 

function sendFormData() 
{ 
	var images = document.form2.image;
	
	for (i = 0; i < images.length; i++)
	{
		if (images[i].checked)
		{
			remoteForm = opener.document.form1; 
			remoteForm.image.value = images[i].value; 
			window.close(); 
		}
	}
} 

--> 
</script> 

<form name="form2"> 
<p>Choose an image:</p>    
<p><input type="radio" name="image" value="image1.jpg"> File Name #1  
<p><input type="radio" name="image" value="image2.jpg"> File Name #2 

<input type="button" value="Choose file and return to main form" onClick="sendFormData();"> 

</form>
Reply With Quote
  #3 (permalink)  
Old 06-27-06, 09:44 AM
losse losse is offline
Newbie Coder
 
Join Date: Jun 2006
Location: Barrie, Ontario, Canada
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Nico... it worked... I'll study that javascript to see what the difference is.
Reply With Quote
  #4 (permalink)  
Old 06-27-06, 10:00 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
To get the value of a radio button you have to loop through all and check which is selected. If you know a bit about Javascript and look at the code you'll see how it works. it's quite obvious.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
need some help with this code buzzby PHP 0 06-20-04 03:07 AM
mysql query loading problem scorpioy PHP 0 05-23-04 03:16 PM
New Web Host, New Problem! justchat PHP 2 09-29-03 02:39 PM


All times are GMT -5. The time now is 11:11 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.