Page 1 of 1
Help With My First PHP Web Application
Posted: Thu Jun 30, 2005 11:57 am
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!
Posted: Thu Jun 30, 2005 12:05 pm
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("e;smallwin.php"e;,"e;smal"e;,"e;width=400,height=400"e;);
smwin.focus();
}
</script>
<form name="e;MyForm"e; method="e;post"e;>
<a href="e;javascript:openWin()"e;>Open Window</a>
<input type="e;hidden"e; name="e;fromsmall"e;>
</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="e;myText"e; id="e;myText"e;></textarea>
<input type="e;button"e; value="e;go"e; onClick="e;upAndClose()"e;>
Posted: Thu Jun 30, 2005 12:26 pm
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.
Posted: Thu Jun 30, 2005 12:37 pm
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="e;MyForm"e; method="e;post"e; action="e;yourpage.php"e;>
Posted: Thu Jun 30, 2005 11:35 pm
by Majoraslayer
Do I need to put that in the parent page or the pop-up page?
Posted: Fri Jul 01, 2005 12:29 am
by Burrito
parent
Posted: Fri Jul 01, 2005 1:07 pm
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.
Posted: Fri Jul 01, 2005 1:44 pm
by Burrito
change the form name back to "MyForm" or change the script to reflect the new name of the form.
Posted: Fri Jul 01, 2005 1:57 pm
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.
Posted: Fri Jul 01, 2005 2:23 pm
by John Cartwright
Moved to Client-Side
Posted: Fri Jul 01, 2005 2:58 pm
by Burrito
Jcart wrote:Moved to Client-Side
thank you
ok just change document.MyForm... to document.editcontent...
although it'd be easier to just change the name of the form back to MyForm.
Posted: Fri Jul 01, 2005 3:27 pm
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.
Posted: Fri Jul 01, 2005 5:28 pm
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'].
Posted: Fri Jul 01, 2005 7:49 pm
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!