Help With My First PHP Web Application

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Help With My First PHP Web Application

Post by Majoraslayer »

I've recently just started studying PHP, so I don't know much about it (yet). Anyway, my little web application is just an experiment.

What I'm needing is for when a user clicks a link, a window pops up with a text area form. When the user clicks submit, the pop-up window needs to close and send the form information to the processing script using the original window. Does anyone know how I might do this? I'm not sure if its possible in PHP, but if anyone knows of another way it might could be done (Javascript) and knows how to write the script, I would appreciate any help!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you WILL need JS to do this if you want to do it in another window and have it posted from the "parent" window.

This is totally JS and as such should be posted in the "Client Side" forum.
ex:

Code: Select all

<script>
function openWin(){
   var smwin = window.open(&quote;smallwin.php&quote;,&quote;smal&quote;,&quote;width=400,height=400&quote;);
   smwin.focus();
}
</script>
<form name=&quote;MyForm&quote; method=&quote;post&quote;>
<a href=&quote;javascript:openWin()&quote;>Open Window</a>
<input type=&quote;hidden&quote; name=&quote;fromsmall&quote;>
</form>

Code: Select all

<script>
function upAndClose(){
   opener.document.MyForm.fromsmall.value = document.getElementById('myText').value;
   opener.document.MyForm.submit();
   window.close();

}
</script>
<textarea name=&quote;myText&quote; id=&quote;myText&quote;></textarea>
<input type=&quote;button&quote; value=&quote;go&quote; onClick=&quote;upAndClose()&quote;>
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

Thanks for helping me out, but I'm having trouble with it. For some reason, after I click submit, instead of going to the processing script it just refreshes the parent page.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

that's because there isn't an action attribute set on the form tag....

you need to tell it where you want it to go:

Code: Select all

<form name=&quote;MyForm&quote; method=&quote;post&quote; action=&quote;yourpage.php&quote;>
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

Do I need to put that in the parent page or the pop-up page?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

parent
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

It doesn't seem to be working right still yet. If you would like to see what its doing, then please check out http://www.zorasdomain.com/phprogram/editable.php . Also, the coding is as follows:

editable.php
<script>
function openWin(){
var smwin = window.open("edithtml.php","smal","width=400,height=400");
smwin.focus();
}
</script>
<form name="editcontent" method="post" action="editorscript.php">
<a href="javascript:openWin()">Edit Page</a>
<input type="hidden" name="fromsmall">
</form>
edithtml.php
<script>
function upAndClose(){
opener.document.MyForm.fromsmall.value = document.getElementById('textcontent').value;
opener.document.MyForm.submit();
window.close();

}
</script>

<textarea name="textcontent" id="textcontent">
<?php
include ("editable.php");
?>
</textarea>
<input type="button" value="save" onClick="upAndClose()">
editorscript.php
<?php
$newcontent=$_POST['textcontent'];

$fh=fopen("editable.php","w");
fwrite($fh,stripslashes($newcontent));
fclose($fh);

include("editable.php");
echo '<p><p><a href="editable.php">Go Back To Editable Page</a>';
?>
If you can find what I'm doing wrong, please let me know.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

change the form name back to "MyForm" or change the script to reflect the new name of the form.
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

I was trying to change the script to reflect the new name, but I apparently left something out. To be honest I have no experience with Javascript, and am just now learning forms and PHP.

I actually got it to work once by putting the form tags in the pop-up page, but script didn't get the $_POST variable correctly, so it overwrote the file with the blank data instead of the data I entered.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to Client-Side
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Jcart wrote:Moved to Client-Side
thank you :wink:

ok just change document.MyForm... to document.editcontent...

although it'd be easier to just change the name of the form back to MyForm.
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

Alright, I wrote the processing script in PHP, but for some reason it isn't getting $_POST['textcontent']. Any ideas on how to get it to work? Whenever I submit the form, the processing script is supposed to overwrite editable.php with what was submitted in the form, but it overwrites it instead with a blank because $_POST['textcontent'] isn't getting the information posted in the form.

Also, I changed it back to MyForm, so other than that it is now working correctly.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

well you're actually getting the variable "fromsmall" assuming you kept what I originally did for you.

so you'd need to use $_POST['fromsmall'].
Majoraslayer
Forum Commoner
Posts: 64
Joined: Thu Jun 30, 2005 11:50 am
Location: In Your Mind...
Contact:

Post by Majoraslayer »

Oh, thanks. Sorry if I seem to be a complete dunce, but Javascript might as well be Greek to me. I'll have to try it later tonight when I get on my own computer, but thanks for the help!
Post Reply