Help With My First PHP Web Application
Moderator: General Moderators
-
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
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!
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!
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:
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;>-
Majoraslayer
- Forum Commoner
- Posts: 64
- Joined: Thu Jun 30, 2005 11:50 am
- Location: In Your Mind...
- Contact:
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:
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;>-
Majoraslayer
- Forum Commoner
- Posts: 64
- Joined: Thu Jun 30, 2005 11:50 am
- Location: In Your Mind...
- Contact:
-
Majoraslayer
- Forum Commoner
- Posts: 64
- Joined: Thu Jun 30, 2005 11:50 am
- Location: In Your Mind...
- Contact:
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
editable.php
edithtml.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>
editorscript.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()">
If you can find what I'm doing wrong, please let me know.<?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>';
?>
-
Majoraslayer
- Forum Commoner
- Posts: 64
- Joined: Thu Jun 30, 2005 11:50 am
- Location: In Your Mind...
- Contact:
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.
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
Majoraslayer
- Forum Commoner
- Posts: 64
- Joined: Thu Jun 30, 2005 11:50 am
- Location: In Your Mind...
- Contact:
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.
Also, I changed it back to MyForm, so other than that it is now working correctly.
-
Majoraslayer
- Forum Commoner
- Posts: 64
- Joined: Thu Jun 30, 2005 11:50 am
- Location: In Your Mind...
- Contact: