Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> [php](simple) Using Functions To Combine Values In A Form, Really simple example on how to combine values with function
matak
post Apr 14 2007, 06:02 PM
Post #1


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



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

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

CODE
<?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

CODE
<?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 wink.gif

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

This post has been edited by matak: Apr 14 2007, 06:17 PM
Go to the top of the page
 
+Quote Post
truefusion
post Apr 14 2007, 06:12 PM
Post #2


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,918
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528



QUOTE(matak @ Apr 14 2007, 02:02 PM) *
CODE
<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,
CODE
<form method="POST">
Go to the top of the page
 
+Quote Post
matak
post Apr 14 2007, 06:16 PM
Post #3


Super Member
*********

Group: Members
Posts: 413
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



Thanks for the tip truefusion smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Free Windowsxp Sp2 Cd From Microsoft(13)
  2. Php Calculator(17)
  3. How To: Change Your Website's Index File(24)
  4. Verifying Email Addresses(9)
  5. Simple C File Handling In Action(4)
  6. Playing Flash Movies Without The One-click Activation: Simple Insertion Of Javascript(4)
  7. What Is A Computer Form Factor(1)
  8. Very Simple Online Now Script(4)
  9. Simple Php Login And Registration System(15)
  10. Php Functions To Send Mail(9)
  11. Php Ftp Upload Form(1)
  12. Simple Javascript And Password System(9)
  13. Functions(9)
  14. A Simple Preg_replace Help Please.(2)
  15. PHP Function To Add Previous and Next Page Feature(5)
  1. Perl For Automated Web Form Search(1)
  2. Finding Good Free Hosting Can Be Frustrating And Costly.(1)
  3. Design A Contact Form In Flex Part 1(0)
  4. Create Dynamic Html/php Pages Using Simple Vb.net Code(1)
  5. Text Size In "fill-in" Form Blanks(2)
  6. Flash Tutorial Simple Motion Tween(0)
  7. About Posting Form(2)
  8. Combine Mediawiki And Wordpress(1)
  9. Design A Contact Form In Flex Part 2(0)
  10. Disabling Right Click Function(9)
  11. Design A Contact Form In Flex Part 3(2)
  12. Submitting A Form In Flex (follow Up Of Sm's Tut)(2)
  13. Password Encryption With Hash Functions(3)


 



- Lo-Fi Version Time is now: 13th October 2008 - 11:21 PM