Friday, July 31, 2009

How do I insert data into a PHP form from another page?

I have an online application form that I want to use, and have job adverts appearing on other pages. I have no knowledge in PHP, so my application form came from an online source.





If I click a link to apply for the job online, how can I insert the job reference number, job title and closing date into the PHP form automatically? I have seen how to do it, but can't remember where.

How do I insert data into a PHP form from another page?
For this type of web page you will usually be storing the job information on the server in some form of database.


When you link to the form page you will probably be passing a parameter of the job reference number like


formpage.php?refno=12345


The Form page will therefore have the job reference number and can retrieve all the information that it needs to fill in the form.
Reply:1. Your HTML form must call a php page (a file with an extention php), and written in php. i.e.:


%26lt;form name=blabla action=useform.php method=POST%26gt;


%26lt;input name=firstname value=""%26gt;


%26lt;/form%26gt;


2. Your file "useform.php" will then use the data received by POST.


You can get all the values posted with:


%26lt;?php


while(list($name,$value) = each($_POST))


$$name=$value;


// or


print_r ($_POST);


?%26gt;


To use the data "passed" by the form to PhP, just echo it:


%26lt;?php


echo ("Firstname: " . $firstname . "%26lt;br%26gt;");


?%26gt;





This will show "[firstname] =%26gt; what-you-enter-in-the-field"


The name of the field will become $firstname in PhP.


Plenty of forms and examples at www.php.net (the official site of PhP).





PS: don't use these b***y pre-made forms! It is totally amateurish (and visible to any professional).
Reply:Somewhere in your page you'll be outputting the html tags that are these fields





%26lt;input type='text' name='job_ref'%26gt;





you need to modify these to include the php variables you are storing this data in.





%26lt;input type='text' name='job_ref' value='%26lt;?php echo $your_job_ref_var_name ?%26gt;'%26gt;





Obviously this approach gets a little painful after a while.





If you don't know php, then you need to take a quick crash course, this will help you:





http://www.php.net/manual/en/language.va...





http://www.php.net/manual/en/language.va...





http://au3.php.net/manual/en/function.ec...


No comments:

Post a Comment