Jump to content

Beginners PHP: Processing Forms Part 2


cfalcon

Recommended Posts

Hi all,

 

I am on Part 2 of the Processing Forms Video in the Beginners PHP series. At around the 4 minute mark, Stefan introduces the 'super global' and the three differnt types specifically for processing forms. After he deletes the $_GET and $_REQUEST, he proceeds to save the $_POST['name_first']; and opened his browser to see a blank page. He then proceeds to add the print command ( print $_POST['name_first']; )and the information "Stefan" appears.

 

I created a form, albeit not the exact same code, but the same layout within a file entited form.php - the same as it is titled within the video. Here is the code:

--------

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">'>http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

 

<style type="text/css">

 

fieldset {

background-color: #E1E1E1;

border: 1px solid #000000;

 

}

.style1 {font-family: Arial, Helvetica, sans-serif}

</style>

</head>

 

<body>

 

<fieldset id="fieldset">

<h1 class="style1"> Processing Forms with PHP - Part 1</h1>

<br />

<form method="post" action="process_form.php">

 

First Name: <br />

<input type="text" name="firstname"/> <br /> <br />

 

Email: <br />

<input type="text" name="email" /> <br /><br />

 

Favorite color:

<input type="radio" name="color" value="red"/> red

<input type="radio" name="color" value="yellow"/> yellow

<input type="radio" name="color" value="blue"/> blue

<br /><br />

 

Favorite Website:

<select name="favoritewebsite">

<option value="killerphp.com">killerphp.com</option>

<option value="yahoo.com">yahoo.com</option>

<option value="google.com">google.com</option>

</select>

<br /><br />

 

Comments: <br />

<textarea name="comment" cols=100px; rows=3px;> </textarea> <br/> <br/>

<input name="Submit" type="button" value="Submit Request >>" />

 

 

</form>

</fieldset>

 

 

</body>

</html>

 

-----------

 

I then created the process_form.php file. Here is the code:

------------

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

<body>

 

<?php

 

print $_POST['firstname'];

 

?>

 

</body>

</html>

------------

 

However my browser gives me this response - Notice: Undefined index: firstname in C:\wamp\www\beginnersphp\process_form.php on line 10

-------------

 

 

- LINE 10 is the( print $_POST['firstname']; ) - Even without the print command, I am getting the same response from the browser.

 

I am using WAMP as the the localhost server and internet explorer 8. What am I not getting right? Line 10 looks correct to me, right? I would appreciate any help given. Thanks!

 

 

 

 

P.S. I tryed posting this in the beginners PHP video forum but it wouldn't allow me for some reason.

Link to comment
Share on other sites

I've tested your exact code (well, I had to change the button element to a "submit" type in order for it to work) and it is working fine for me.

 

However, it only works if you open the form.php file first, fill out the form and submit. The next page should display the contents of the input field and not display an error.

 

If you refresh the process_form.php page after you do that, or try to view the process_form.php page without first going to form.php and pressing the submit button, you will get an error.

Link to comment
Share on other sites

I've tested your exact code (well, I had to change the button element to a "submit" type in order for it to work) and it is working fine for me.

 

However, it only works if you open the form.php file first, fill out the form and submit. The next page should display the contents of the input field and not display an error.

 

If you refresh the process_form.php page after you do that, or try to view the process_form.php page without first going to form.php and pressing the submit button, you will get an error.

 

 

THANK YOU!! Yes, i think the "button" should have been "submit." I tried it as button and it didn't work. I almost feel a bit foolish cause I know better. Thank you very much for the help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...