noobie looking for help

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
lemonsprig
Forum Newbie
Posts: 2
Joined: Mon Jul 28, 2003 1:17 pm

noobie looking for help

Post 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
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
lemonsprig
Forum Newbie
Posts: 2
Joined: Mon Jul 28, 2003 1:17 pm

Post 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
rob.weaver
Forum Newbie
Posts: 8
Joined: Tue Apr 22, 2003 11:18 am
Location: Houston, TX USA

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply