Skip navigation
peterattrsb
Currently Being Moderated

help with forms

Feb 29, 2012 2:47 PM

I am quite new to Dreamewaver CS4 and I am presently working my way through the book by Jeffery Bardzell "training from the source. I have reached lesson 5 "passing data between pages. I have created the first and last name text fields on the form and then run the form through the server. I works fine and displays the first and last names on the form processor ie "thank you ,john smith, for filling out my form" The book then tells me to open the form processor and it should look like "thank you ,, for filling out my form, however it displays:

 

Thank You, Notice: undifined index:firstName in c:\xampp\htdocs\newland\test_form_processor.php on line 9.

                                undifined index lastName in c:\xampp\htdocs\newland\test_form_processor.php on line 9

,for filling out my form.

 

Could someone tell me what i have done wrong. I followed the book word for word and i have also checked the code on my page with the code on the "completed lesson" on the CD. theyr'e both identical.

 

Any help would be apreciated

 
Replies
  • Currently Being Moderated
    Feb 29, 2012 3:28 PM   in reply to peterattrsb

    Have you been in touch with Jefferey Bardzell, after all he is the one that sold the book to you.

     

    Failing that, you could show your code for us to see.

     

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 29, 2012 4:23 PM   in reply to peterattrsb

         peterattrsb User  

     

     

    Not sure how to do that. Iv'e tried copy and paste but the paste doesn't work on this

     

     

    I have just copied and pasted your last post. Not sure why it does not work for you. Please remember that for the PC you can paste using ctrl-v

     

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 1, 2012 3:35 PM   in reply to peterattrsb

    When you view the document in a browser, the URL will show

    c:\xampp\htdocs\newland\test_form_processor.php

    or similar. If we add the URL variables that the document asks for, Bob's your uncle. Add the highlighted as in

    c:\xampp\htdocs\newland\test_form_processor.php?firstname=Uncle&lastname=Bob

    The result will be

    Thank you, Uncle Bob, for filling out my form.

    What this means is, that the document that calls this document should include the URL variables in the link.

     

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 1, 2012 4:55 PM   in reply to peterattrsb

    We would need to see how you are setting the cookie. Cookies can  expire as soon as the browser is closed.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 1, 2012 7:55 PM   in reply to peterattrsb

    I guess the book is wrong! Try to get your money back. If you want an outcome as you have described the line reading

    <p>Thank you,<?php echo $_GET['firstName']; ?> <?php echo $_GET['lastName']; ?>, for filling out my form. </p>

    should read

    <p>Thank you,<?php echo (isset($_GET['firstName']) && isset($_GET['lastName'])) ? $_GET['firstName'].' '.$_GET['lastName'] : ' '; ?>, for filling out my form. </p>

    The result will be

    Thank you, , for filling out my form.

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2012 12:31 AM   in reply to peterattrsb

    peterattrsb wrote:

     

    Thanks it worked doing that I have just re looked at the code in my page and also the code in the lesson finished and theyre identical.

     

    This is what it should say according to the book:

     

    "thank you ,, for filling out my form"

     

    however it displays: 

     

    Thank You, Notice: undifined index:firstName in c:\xampp\htdocs\newland\test_form_processor.php on line 9.

                       Notice: undifined index lastName in c:\xampp\htdocs\newland\test_form_processor.php on line 9

    ,for filling out my form.

     

     

     

    But it only displays the 'Notice: undifined index' IF you run it through the browser, right. I think what the book means by 'open' the 'test_form_processor.php' page is open it in Dreamweaver then the page will look like it says:

    "thank you ,, for filling out my form"

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2012 7:29 AM   in reply to peterattrsb

    peterattrsb wrote:

     

    I tried the same experiment using the completed lessons form on the CD that came with the book and I got the same results. I then changed the code to the one gramps suggested and it worked OK.

     

    I have to say someone new to Dreamweaver and following the book word for word would expect it to work. I think the book could be a little clearer and if there is the possibility that an error could occur then the book should at least have some reference that this could happen. It would save someone like me spending hours looking through the code thinking they had done something wrong when in actual fact they hadn’t. It’s not a cheap book I paid £ 39.33 a few years ago so I think it would have gone up since then.

    When I have worked my way through this book I am moving on to Dreamweaver CS5 Training form the source by David Powers. Hope this book is right.

     

    Thanks for all your help with this. It was really appreciated. At lease i know where to come to if i get stuck again.

     

    Thanks

     

    Paul

     

    The first instance ("thank you ,, for filling out my form,) was never going to work as the page would never receive the correct information to return anything if just opened in the browser WITHOUT either going through the form or as gramps solution passing the variables firstName & lastName in the url

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2012 8:22 AM   in reply to peterattrsb

    I'd say you have to set the 'cookie' first:

     

     

    <?php

    setcookie("firstName", "Uncle");

    setcookie("lastName", "Bob");

    ?>

     

     

    <!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>

    <title>Cookie Test</title>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    </head>

     

    <body>

     

    <p>Thank you, <?php echo $_COOKIE['firstName'];  ?> <?php echo $_COOKIE['lastName']; ?>for filling out my form. </p>

    </body>

    </html>

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 2, 2012 9:42 AM   in reply to peterattrsb

    >In the bindings panel click the new binding button, choose cookie

    >variable and type firstName. Repete step 7 to add lastName cookie to the bindings panel.

    >

    >Thats how it tells me to create the cookies.

     

    They don't tell you to set an expiration time? Without a specified expiration, the cookie will expire when the browser is closed. So, it seems everything is working as expected.

     

    >even though you closed the browser the data persisted

    >because it was saved on your hard drive as a cookie

     

    This is wrong. If you don't specify an expiration, cookies expire when the browser is closed.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 3, 2012 5:27 PM   in reply to peterattrsb

    <?php echo (isset($_GET['firstName']) && isset($_GET['lastName'])) ? $_GET['firstName'].' '.$_GET['lastName'] : ' '; ?>,

    In plain English

    echo

    print/show following echo. In our case we need a conditional statement to choose what will be shown. The conditional statement that I have used is called a ternary operator. This does the same as if condition is true then else this

    (isset($_GET['firstName']) && isset($_GET['lastName']))

    Our condition: firstName and lastName values are not empty

    ?

    if true, i.e. there is a value for both of the variables

    $_GET['firstName'].' '.$_GET['lastName']

    then go ahead and print the above

    :

    if false, i.e. there is no value for BOTH the variables

    ' '

    then print nothing

     

    The reason why we have to use the conditional statement is probably already clear to you, it is to make sure that we do not get error messages if the condition cannot be met.

     

    Gramps

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 5, 2012 1:49 PM   in reply to peterattrsb

    >if ($_GET['error'] == "notnumeric")

     

    I'm not sure if this is the line causing the error, but here you are testing the value of a variable without first testing if it has been set. Always test if an array element is set before trying to access the value. http://us3.php.net/isset

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2012 9:49 AM   in reply to peterattrsb

    <?php echo (isset($_GET['firstName']) ? $_GET['firstName'].' '. ?>

     

     

    I'd write it like:

     

    <?php

     

    $firstName = $_GET['firstName'];

     

    if (isset($firstName)) {

    echo $firstName;

    }

    else {

    echo "First name not set";

    }

     

    ?>

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2012 10:09 AM   in reply to osgood_

    Or following your technique like below:

     

    <?php echo (isset($_GET['firstName'])) ? $_GET['firstName'] : ' '; ?>

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 10, 2012 1:18 PM   in reply to peterattrsb

    Text entered into a text area is plain text, not html. Line feeds and carriage returns are considered whitespace in html. So if you want to display the text and have line feeds you need to convert them to <br>. Use the nl2br() function.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Incoming Links

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points