Jump to content
xisto Community
Sign in to follow this  
matak

[php](simple) Using Functions To Combine Values In A Form Really simple example on how to combine values with function

Recommended Posts

I just learned this simple method on how to use functions to combine two values from a form. First we create ourselves a simple POST form

<form method="POST">Name: <input type="text" name="nickname">Location: <input type="text" name="location"><input type="submit" value="Input"></form>

Now we add this php to that same file

<?php$nick = $_POST['nickname'];$location = $_POST['location'];function information($nick, $location){	echo 'My nick is '.ucfirst($nick).'<br>My location is '.$location;	}information($nick, $location);?>

that code is similar to this one

<?php$nick = $_POST['nickname'];$location = $_POST['location'];function information($nick, $location){	return 'My nick is '.ucfirst($nick).'<br>My location is '.$location;	}$combine = information($nick, $location);echo $combine;?>

It's up to you to decide which one to use ;)

And that is it. I really find this code quite useful for understanding functions in PHP. Hope it does the same for you.
(here's the example)

EDIT: Edited form as truefusion said below
Edited by matak (see edit history)

Share this post


Link to post
Share on other sites

<form action="<?php $PHP_SELF; ?>" method="POST">
If i'm not mistaken, you can do without the action="<?php $PHP_SELF; ?>" part since it'll be loading the same page. That is,
<form method="POST">

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.