Welcome! Log In Create A New Profile

Advanced

PHP Four - Working with HTML Forms

Posted by 77928490 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
PHP Four - Working with HTML Forms
February 17, 2013 09:22PM
Ok the coding is getting more challenging. It took a while to get to grips with this section. The javascript example went way over my head. hopefully only for now. Otherwise the tutorial is pretty good and taking us through it. Just feel i need tons of practice.

Cheers, now onto PHP Five.
avatar Re: PHP Four - Working with HTML Forms
February 18, 2013 12:02PM
Same here!! This got quite a bit challenging, but still nice!!
Re: PHP Four - Working with HTML Forms
February 21, 2013 06:52AM
Getting tricky...gotta keep your wits about you and watch the punctuation. Getting there though! Done!
avatar Re: PHP Four - Working with HTML Forms
February 21, 2013 08:41AM
Agree te punctuation caught me a couple of time!! Forget one > and something does not work. So far so good.
avatar Re: PHP Four - Working with HTML Forms
February 24, 2013 09:24PM
I would not worry to much about the JS as this is a PHP course - try and see JS as an added benefit, something to enrich your code but not the foundations.

Punctuation is more important in coding than in language (I know some grammar Nazis that is going to kill me for this) smiling bouncing smiley

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
Re: PHP Four - Working with HTML Forms
February 25, 2013 09:26PM
Wowzers!! this was hectic, hahaha, I guess it always becomes harder before it becomes easier.
Re: PHP Four - Working with HTML Forms
February 26, 2013 07:48PM
Hi guys, Did you notice after running this code:

if (isset($_POST['Submit'])) {

$username = $_POST['username'];

if ($username == "letmein"winking smiley {
print ("Welcome back, friend!"winking smiley;
}
else {
print ("You're not a member of this site"winking smiley;
}
}

after pressing submit and entering "letmein" or anything else in the text box nothing is shown, i thought the (isset($_POST['Submit'])) was suppose to set it to not clicked only then print something out but i noticed totally nothing is printed out on the screen, i have a feeling its the braces, still debugging it hey...did u guys notice this?..thats on the page "Checking if the Submit Button of a HTML Form was Clicked " in Chapter 4....otherwise forms, radio buttons, check boxes...lovin it all......&ru
avatar Re: PHP Four - Working with HTML Forms
February 26, 2013 08:30PM
77998847, please use formatting code when posting code. It's a nightmare to copy/paste after the forum has converted all the symbols to smiles.

The code you posted is just for example purposes. Once you move on you will see it in action.

Also, this line

Language: PHP
if (isset($_POST[';Submit';])) {

should be

Language: PHP
if (isset($_POST[';Submit1';])) {

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
Re: PHP Four - Working with HTML Forms
February 26, 2013 10:49PM
why?
if (isset($_POST['Submit1'])) {

confuseconfused smiley

I dont see anything wrong with his code, but then i have to see the form as well to be sure.
avatar
Mac
Re: PHP Four - Working with HTML Forms
February 27, 2013 07:51AM
As implied, if the submit button's name in the form is Submit1, then $_POST must also be Submit1 else the form will not be processed.
Re: PHP Four - Working with HTML Forms
February 27, 2013 10:09AM
Thanks a lot mac and shado, indeed i noticed my buttons name was different and yes i will use formatted code from now on
Language: PHP
if (isset($_POST[';Submit';])) {

instead of

Language: PHP
if (isset($_POST[';Submit1';])) {

smile
Re: PHP Four - Working with HTML Forms
February 28, 2013 11:36AM
hosit guys.. worked through this section quick quick..

just one thing..

is there a specific reason that in the last tut they use this piece of code to check for the checkboxes:

Language: PHP
if (isset($_POST[';ch2';])) {   $ch2 = $_POST[';ch2';];   if ($ch2 == ';word';) { $ch2 = ';checked';; } }

and not just :

Language: PHP
if (isset($_POST[';ch2';])) { $ch2 = "checked"; }

the return from the form is a true or false anyway so why are they checking the value of the input when all of them have different names. Is the example for when you use the same name in the input but different values?

Student number : 7803-010-2
Email and Gtalk for support : wilcovandeijl@gmail.com
Re: PHP Four - Working with HTML Forms
February 28, 2013 02:18PM
Hi, I don't know anything about the section since I haven't got the study material.... but you are correct if it is a checkbox and not a radio, then the test that is needed it's isset only...

so:

Language: PHP
if ( isset( $_POST[';ch2';] ) ) { // Do something }

Should be enough, since if the checkbox it not checked on the form then the $_POST won't contain the 'ch2' at all.... I strongly agree with you wilcovandeijl.... unless it is type="radio", then you can do the second check...cool
avatar
Mac
Re: PHP Four - Working with HTML Forms
March 01, 2013 08:19AM
I think it is to explain the logic behind to all. All PHP code can be bettered, so never see it as a rule how to code. This is the thing - you apply your logic (as you have done), and code to it.
Re: PHP Four - Working with HTML Forms
March 01, 2013 11:37AM
Section4 was oky, just learn that there is a couple of syntax problems when using the tutorial like example "= =" instead of "==", but it is nothing to get stressed out.
I also like to use comments in my programming, and had "learned" that you Use "<!-- -->" for comments in html.
It's nice playng with the little programs we get to practice and I've figgured out you can use the dot "." to put strings together, but I think its also in the later tutorials.

PHP is more fun that I thought it would bethumbs up
avatar
Mac
Re: PHP Four - Working with HTML Forms
March 01, 2013 11:51AM
Those syntax errors are due to the copy process....I just never noticed it until you guys brought it up! That said, perhaps an unintended consequence is that it makes you aware of syntax errors - which is 80% of errors!
avatar Re: PHP Four - Working with HTML Forms
March 03, 2013 01:08AM
Good section, think we'll be using lots of forms. Also noticed 'Submit' should be 'Submit1' - was bit puzzled at first, so glad I'm not the only one that had that issue.
I was also wondering if there is a rule of thumb for when it's good to use variables and when it's better to just use the actual value, like in the case of the Switch statement or If, like mentioned here:

wilcovandeijl Wrote:
-------------------------------------------------------
> hosit guys.. worked through this section quick
> quick..
>
> just one thing..
>
> is there a specific reason that in the last tut
> they use this piece of code to check for the
> checkboxes:
>
>
Language: PHP
> if (isset($_POST[';ch2';])) { > > $ch2 = $_POST[';ch2';]; > > if ($ch2 == ';word';) { > $ch2 = ';checked';; > } > } >
>
> and not just :
>
>
Language: PHP
> if (isset($_POST[';ch2';])) { > $ch2 = "checked"; > } >
>
> the return from the form is a true or false anyway
> so why are they checking the value of the input
> when all of them have different names. Is the
> example for when you use the same name in the
> input but different values?
Re: PHP Four - Working with HTML Forms
March 03, 2013 05:40PM
Completed the section on Forms - what I encountered has already been mentioned.

I found the sections on getting values from forms, checkboxes and Radio buttons particularly interesting. thumbs up
Re: PHP Four - Working with HTML Forms
March 06, 2013 02:17PM
Just a quick question, forms is what i figure we will be using plenty of. In terms reporting or generating reports of our data, is a form in php essentially just showing or printing results onto a new page as in

Language: PHP
<FORM name ="form1" Method ="post" action ="reportform.php">

or its now more mySql related and we may have to use items such as crystal reports.

..&ru..
avatar
Mac
Re: PHP Four - Working with HTML Forms
March 06, 2013 02:32PM
You will use forms to capture data and insert the info that was filled in on it into a database. If such information is to be edited, it will be drawn back into a form ready to be edited. Data from the db you draw using sql queries and php code.

You can add to and edit information in a db in 2 ways - using a form, or directly in the db (using phpmyAdmin, for example). You will not give any person access to your db, so you are left with forms.
Re: PHP Four - Working with HTML Forms
March 06, 2013 03:11PM
thnx mac

..&ru..
Re: PHP Four - Working with HTML Forms
March 11, 2013 12:57PM
Had a slow start, now that I have the study material am trying to get to speed. Strugled with the installation but managed to get XAMPlite installed & running. Old dos commands have been helpful to copy files to my working directory especially when the pictures 'kitten' were in the code but not found on the CD. Initially was using notepad as editor but now I find PHPedit better as I can test my codes within the editor. Chapter 4 is quite interesting, have gone through it and am now embarking on chp 5. It is advisable to have a look at the HTML syntax for Forms to understand this chapter.
avatar Re: PHP Four - Working with HTML Forms
March 11, 2013 11:54PM
HTML Forms completed. I had a whole lot of syntax error including:

Language: PHP
if (isset($_POST[';Submit1';])) {
and
Language: PHP
if (isset($_POST[';Submit1';])) {

Now there is much clarity as to how PHP applies and works in HTML files.
Re: PHP Four - Working with HTML Forms
March 18, 2013 09:26AM
This time "when i studied it about 2 weeks ago" I made sure I can code out complete forms without looking at an example, because it is not the first time that I use forms. Forms are everywhere and I would say this is one of the most important topics in this PHP course. If you know forms and how to use the $_POST['name'] and $_GET['name'] statements you will be well off with learning arrays to extract information from a element or "placeholder". I am making it a point to research and study on a deeper level with forms.

Student Number: 78042879 (Part Time Courses)
Re: PHP Four - Working with HTML Forms
March 18, 2013 03:30PM
This was quite a difficult section. Took me some time to get to grips with the code, the coding is getting a bit more difficult now. The Java Script section is pretty hard as I remember from the previous web design course we did, we learn't Java Script, and I did struggle on that section but with some practice all will come together. Now on to PHP 5 smiling smiley
Re: PHP Four - Working with HTML Forms
March 18, 2013 09:15PM
Guys remember to check the section on validating user inputs from the textbook. A programmer can't predict how the user will make inputs onto the form, so it's best to guide and validate the user inputs and make sure that your application functions as expected.
Re: PHP Four - Working with HTML Forms
March 20, 2013 10:26AM
done, easy enough
avatar Re: PHP Four - Working with HTML Forms
March 20, 2013 01:02PM
Great refresher chapter.

I usually use:

Language: HTML
<form method="post" action="posttodb.php">

I have also recently seen my Wordpress firewall sending me the following messages via e-mail:

LOGTIME: 

FROM IP: http://whois.domaintools.com/173.243.112.171
URI: 
METHOD: GET
USERAGENT: Java/1.4.1_04
REFERRER: N/A

Could this METHOD: GET be a hacking attempt, because I sometimes get about 40 of these in a row.eye popping smiley
avatar Re: PHP Four - Working with HTML Forms
March 20, 2013 11:29PM
I always wondered what the GET and POST method does in a form.
There are definitely times when you want to use POST.
Certain information is sensitive and you don't want it to be visible in the address bar.
Re: PHP Four - Working with HTML Forms
March 21, 2013 03:18PM
I liked the way w3schools made the differences between GET and POST clear:
http://www.w3schools.com/tags/ref_httpmethods.asp

Go this directly from the link above:

Two commonly used methods for a request-response between a client and server are: GET and POST.

GET - Requests data from a specified resource
POST - Submits data to be processed to a specified resource

The GET Method
Some other notes on GET requests:

GET requests can be cached
GET requests remain in the browser history
GET requests can be bookmarked
GET requests should never be used when dealing with sensitive data
GET requests have length restrictions
GET requests should be used only to retrieve data

The POST Method
Some other notes on POST requests:

POST requests are never cached
POST requests do not remain in the browser history
POST requests cannot be bookmarked
POST requests have no restrictions on data length

When thinking of website usability I thought important to note that GET can be bookmarked and POST cannot.
I guess always using POST to be on the safe side is not a good idea.
avatar Re: PHP Four - Working with HTML Forms
March 21, 2013 11:54PM
40 times in a row with in a set amount of time will be seen as a hacking attempt smile

riaand-77568672 Wrote:
-------------------------------------------------------
> Could this METHOD: GET be a hacking attempt,
> because I sometimes get about 40 of these in a
> row.eye popping smiley

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
Re: PHP Four - Working with HTML Forms
March 23, 2013 04:55PM
get yourself wordfence, its a must. hackers have a field day on wordpress

riaand-77568672 Wrote:
-------------------------------------------------------
> Great refresher chapter.
>
> I usually use:
>
>
Language: HTML
> <form method="post" action="posttodb.php"> >
>
> I have also recently seen my Wordpress firewall
> sending me the following messages via e-mail:
>
>
> LOGTIME: 
> 
> FROM IP:
> http://whois.domaintools.com/173.243.112.171
> URI: 
> METHOD: GET
> USERAGENT: Java/1.4.1_04
> REFERRER: N/A
> 
>
>
> Could this METHOD: GET be a hacking attempt,
> because I sometimes get about 40 of these in a
> row.eye popping smiley

http://capetown-airport.co.za/
Re: PHP Four - Working with HTML Forms
March 24, 2013 10:53AM
I see from the posts to the forum some students found this chapter it easy and others more challenging. I definitely fell into the latter category. Will have to keep notes next to me anytime I do this PHP coding as will never know it out of my head. I am hoping a few things will be made clearer once my textbook arrives.

Thanks guys for the warnings of the error in coding in the course material-helped a lot.

Find the lack of error messages frustrating as often the php simply doesn't run if there is a syntax error. Spent a long while trying to find a syntax error in one of the exercises only to realize php wasn't running as I hadn't started EasyPHP - won't make that mistake again.

It is rewarding getting the exercises to run so am looking forward to next section.
avatar Re: PHP Four - Working with HTML Forms
March 24, 2013 01:54PM
I disagree, I'm a wordpress developer and as long as you keep your wp software updated, limit plugins, stay away from dodgy plugins and practice good password practises your chances are you wont get hacked.

I've built many wp websites and over the last 3 years I've only had one site hacked and that was due to the client not keeping it updated.

Wordfence is a nice little plugin which I often use on sites that carry international content but if your wordfence or any other part of the site is outdated you can still be hacked.

Never rely on just wordfence to protect your site.

kreason_77840070 Wrote:
-------------------------------------------------------
> get yourself wordfence, its a must. hackers have a
> field day on wordpress
>

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
Re: PHP Four - Working with HTML Forms
March 29, 2013 06:32PM
Done
Re: PHP Four - Working with HTML Forms
April 02, 2013 12:13AM
if (isset($_POST['Submit'])) {
$use_rname = $_POST['username'];
if ($user_name == "letmein"winking smiley {
print ("Welcome back, friend!" );
}
else {
print ("You're not a member of this site"winking smiley ;
}
}. This does not get the value of my textbox if. If i remove the fist line-if (isset($_post['submit'])) and say $use_name="letmein" it works. Plz give me the solutions
avatar
Mac
Re: PHP Four - Working with HTML Forms
April 02, 2013 07:52AM
First use the formatted code button on the reply form to post code...

You have 3 different spellings of the varibale username
Sorry, only registered users may post in this forum.

Click here to login