Page 1 of 1

noobie looking for help

Posted: Mon Jul 28, 2003 1:17 pm
by lemonsprig
Hi all,

I have recently started looking at php etc so bear with me. I have created apage which launches a popup window. On this window a user can enter information into a text box. When the user clicks a button I want to be able to grab the info in the text box and then fire it back into a database. I then want to close the pop up window and return focus to the original calling page.

Whilst I am ok to insert the data to the database i am struggling to actually get back the info from the form (never was nay good with forms)

Appreciate any help with this, as its causing me sleepless nights

Thanks

Ian

Posted: Mon Jul 28, 2003 1:21 pm
by m3rajk
well.. to start with, if you create the pop up via javascript, then you close it via javascript

now you just need to use that $_POST[] array to tell when to give the user the close link.

i would have a error checking functionin the pge so that when it calls itself it'll check for errors and return them if there were any

and call a different function to make the page if it was all good, and that function will give the close link as well as letting the user know it was successful

Posted: Mon Jul 28, 2003 1:54 pm
by lemonsprig
ok to uncofuse my simple mind a little lets take a step back and ignore the opening and closing of the pop up.

I am trying to test this with the following code

<form action="" method=POST>
<input type="text">
<select name="size">
<option value="small">small</option>
<option value="medium">medium</option>
<option value="large">large</option>
</select>
<input type="submit">
</form>

<?php
echo "$_POST[0]"
?>

when i click the submit button it simply blanks what is in the text box. And the echo function displays nothing.. I am wondering if somethinf fundamental is flawed with my thinking here

Posted: Mon Jul 28, 2003 3:11 pm
by rob.weaver
if you are sending it back to itself... remember to use the

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

otherwise, you need to fill something in where it says action=""

rob

Posted: Tue Jul 29, 2003 6:22 am
by twigletmac
You need to give your form elements names so that they can be identified by PHP. Try this:

Code: Select all

&lt;form action="&lt;?php echo $_SERVER&#1111;'PHP_SELF']; ?&gt;" method="POST"&gt; 
&lt;input type="text" name="textinput" /&gt; 
&lt;select name="size"&gt; 
    &lt;option value="small"&gt;small&lt;/option&gt; 
    &lt;option value="medium"&gt;medium&lt;/option&gt; 
    &lt;option value="large"&gt;large&lt;/option&gt; 
&lt;/select&gt;
&lt;input type="hidden" name="action" value="post" /&gt;
&lt;input type="submit" /&gt; 
&lt;/form&gt;
Now for when the form is submitted you can do:

Code: Select all

<?php 
if (!empty($_POST['action']) && $_POST['action'] == 'post') {
    echo 'The value of $_POST[''textinput''] is: '.$_POST['textinput'];
    echo '<br />';
    echo 'The select value chosen was: '.$_POST['size'];
}
?>
Mac