Getting data from forms

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
landi
php-forum GURU
php-forum GURU
Posts: 388
Joined: Thu Mar 15, 2012 3:59 pm

Tue Mar 20, 2012 12:19 am

Hi,
when you try this, what happens?

Code: Select all

$value = $_POST['my_text_field'];
var_dump($value);
 
- A
throwcode
php-forum Active User
php-forum Active User
Posts: 34
Joined: Mon Sep 05, 2011 7:35 am

Tue Mar 20, 2012 7:10 pm

Hi landi,

If its a text field and it has no default value and the user did not enter any data then it should return an empty string.

TC
landi
php-forum GURU
php-forum GURU
Posts: 388
Joined: Thu Mar 15, 2012 3:59 pm

Wed Mar 21, 2012 12:25 pm

Hi TC,
Thank you for taking the time to post, but I'm not the original poster :) I wouldn't have mentioned it except you did it again on a different post.

And, err, yes, I knew that. I just wondered why the original poster didn't try it for himself. I thought it might be educational to learn to use var_dump, sort of reduce the overhead of the next 50 questions if he figures out something for himself (and var_dump is particularly useful).

So, mDennis10, if you're listening, it would be helpful if you at least tried a solution before asking for help. And just to show there's no ill feeling, be aware that some inputs (such as checkboxes) do NOT return a blank string if they are not checked, they don't return anything (so $_POST['myCheckbox'] is undefined if the box isn't checked).

- A
throwcode
php-forum Active User
php-forum Active User
Posts: 34
Joined: Mon Sep 05, 2011 7:35 am

Wed Mar 21, 2012 6:13 pm

Hi landi,

Sorry about that, I think it was late at night.

If we are giving advice to newbies I would have to say set up a development environment that allows you to debug by stepping through the script and seeing the variables set each step of the way. PHP is a ridiculously flexible language which gives us all a lot of opportunity to make mistakes.

TC
landi
php-forum GURU
php-forum GURU
Posts: 388
Joined: Thu Mar 15, 2012 3:59 pm

Wed Mar 21, 2012 11:06 pm

throwcode wrote:Hi landi,
PHP is a ridiculously flexible language which gives us all a lot of opportunity to make mistakes.
Yes, both a joy and a problem at the same time! :)
stevemcgee
New php-forum User
New php-forum User
Posts: 20
Joined: Mon Feb 27, 2012 3:38 am

Mon Mar 26, 2012 9:33 pm

You can easily solve your problem with:‭ ‬$‭_‬GET.‭ ‬The predefined‭ ‬$‭_‬GET variable is used to collect values in a form with method‭="‬get‭"‬.

Hire PHP Developers - Experienced PHP Developers available on Full-Time, Part-Time & Hourly Basis.
landi
php-forum GURU
php-forum GURU
Posts: 388
Joined: Thu Mar 15, 2012 3:59 pm

Tue Mar 27, 2012 3:13 am

stevemcgee wrote:You can easily solve your problem with:‭ ‬$‭_‬GET.‭ ‬T
What problem?
User avatar
engrmudasirmalik
New php-forum User
New php-forum User
Posts: 14
Joined: Wed Jan 11, 2012 11:39 am
Location: Bahawalpur Pakistan
Contact:

Tue Mar 27, 2012 1:17 pm

dude try this one it might help you

Code: Select all

$yourValue = $_POST['txt_field_name'];
var_dump($yourValue );
oneclickit
New php-forum User
New php-forum User
Posts: 1
Joined: Mon May 24, 2021 5:52 am

Mon May 24, 2021 5:58 am

The predefined‭ ‬$‭_‬GET variable is used to collect values in a form with method‭="‬get‭"‬.

Hire Software Developers - Experienced best Software Developers available on Full-Time, Part-Time & Hourly Basis.
Post Reply