Page 1 of 1
How to Carry form values by PHP
Posted: Mon Jul 20, 2009 5:50 pm
by mikes1471
Hey
I'm looking to carry a value from a dropdown form or radio button (using an onclick or onchange function which i've not done before :S) so on the selection of the value the form is submitted but not to a database, I just want to submit the value of the selection to a sum on the following page so if on page1.php you select value '2', page2.php has the ability to say "You chose number 2!" or contribute the value to a sum etc.
I then want them to be able to select another value on page2.php which appears on page3.php you chose (e.g) '7' and so on and so on on potentially infinate pages, so a single value needs only to be stored from one page to the next.
I hope this makes sense to someone lol, can this be done using PHP without the use of a database? If so, how?
Best Regards
Mike
Re: How to Carry form values by PHP
Posted: Mon Jul 20, 2009 6:56 pm
by alex.barylski
1. Propagate the value in the URI
2. Persist the values in the next pages form
3. Use SESSION variables which is what their there for
Re: How to Carry form values by PHP
Posted: Mon Jul 20, 2009 7:03 pm
by califdon
I think it will help you to focus on one part of this at a time. A database doesn't need to be involved at all. All you're talking about is sending HTML Form data to another script. That's done by setting 2 parameters in the <FORM ... > tag:
- method='post' or method='get' (usually you want to use 'post')
- action ='.....' (the URL of the script that's going to receive the data)
and for each <input ... > tag, you must have a name='...' attribute.
In that action script, you just recover the data from the $_POST array that was created by submitting the form on the first page. It's good practice to assign the data items to variables so you can handle them more easily. If you had 3 <input ... > tags, for example, with names of 'name', 'age', and 'dog', you could have:
Code: Select all
$name=$_POST['name'];
$age=$_POST['age'];
$dog=$_POST['dog'];
It's important, though, that you apply some security measures to such variables before you use them for anything important, such as storing in a database or accessing files, because they are vulnerable to hackers inputting potentially harmful data.
I hope that will get you oriented, but do understand that this forum is no substitute for reading the manual and tutorials. We can't possibly
teach you how to program in a forum! We will try to answer specific questions that stump you, but you have to take the initiative to study the basics on your own.
Re: How to Carry form values by PHP
Posted: Mon Jul 20, 2009 8:46 pm
by mikes1471
califdon wrote:
I hope that will get you oriented, but do understand that this forum is no substitute for reading the manual and tutorials. We can't possibly teach you how to program in a forum! We will try to answer specific questions that stump you, but you have to take the initiative to study the basics on your own.
No, I know that and I appreciate everyones input, my aspirations are ahead of my knowledge at the moment and while I know how to post to and get from databases and use sessions to display various areas of my website to people who are logged in, my focus was on the 'Returning Values from user-defined functions' section of my Sams teach yourself manual but I was still unclear on how to apply it to the task but thanks all, you have made things clearer for me now