Click to See Complete Forum and Search --> : js with php
daed17
01-12-2004, 06:31 PM
I have several pages written in php that post back to the page using php_self in the forms.
How can I use javascript to pull information that will allow me to fill in the form based on their choice and then allow the user to send the form?
Have got something like ...
<form action="<?=$_SERVER["PHP_SELF"]?>" name="_form" method="get">
... on your page?
If so, all the values of the elements on the form ... text boxes, hidden fields, etc. ... are sent back to the php page when the form is submitted.
Does that help?
daed17
01-12-2004, 06:45 PM
Right now the form uses...
<form name="form1" method="post" action="<?php echo $PHP_SELF?>">
and what I would like to do is use js to allow them to insert data into the form before the form is sent.
lisawebs
01-12-2004, 06:52 PM
2 approaches:
A)
if you simply want to handle, validate, store
form data before submit it, using JS,
then use <input type=hidden...> fields
when you were ready to submit the form
just pass the JS values into the hidden form fields.
b)
if you want to store the php values after submit it,
when page returns,
then simply write JS using echo("<script>")... etc
but REMEMBER to place a " \n " into the echo,
before to close the quotes,
Also, be aware that very long strings will be a problem
you should overcome with a little of programming.
hope this could be of any help
Yes, your line is OK for now, but, in later versions of PHP, this won't always work.
Best to do it the 'long-term' way.
Actually, I still don't think you need javascript, just PHP.
Load up your page ... less any personal data, of course ... and I'll show you how to set it up.
If it's a big file, upload load it as a .txt file.
daed17
01-12-2004, 07:01 PM
Yeah it does, but I would like for it to post back to the text field so they can see it in the form.
Here is an example of what is going on....
Let's say your looking for someone with the last name of McDow but you can't remember the first name but you also know their street or phone number... then using a javascript when they enter McDow then it shows a list of names and other info, then you choose say D McDow and it will fill in the form with the info.
lisawebs
01-14-2004, 11:26 AM
Im not sure what you want to do
daed,
You need to be much more careful in your explanations, because we cannot see what you want.
The standard way of handling forms is this:
1) Users enter data onto an HTML form
2) Javascript does some error-checking (making sure required fields are filled in, etc.) before submitting the form to a 'response' php script.
3) PHP does it's own error-checking before processing the data
Every form-response is essentially a more-or-less elaborate version of this. For example:
1) An HTML form is pre-filled by PHP.
2) The PHP that processes the data is on the same page as the form and thus can display a second, or third form, depending on the first lot of data.
3) The error-checking (standard version - 3) can decide whether to process the data or, re-fill and show the form with an explanation.
Do you think you may be able to explain your needs in this format?