Jump to content

auto fill in form php help!!!!!!!!


mattchris18

Recommended Posts

Hey,

 

On the website i am making i have 20 pages, each page has a individual comedian offering his services to be hired. I have set the site up simply, no database or anything.

 

On each of these pages is a simple "Book Me" button which links to:

 

/bookme.php

 

On the book me page is a form, which the clients fill in to make the booking. Its very simple and basic, some would say primitive.

 

All page my pages are saved as PHP files, and i would like to know how to make it so a form field on the bookme.php is automatically filled in with the name of the comedian they are booking.

 

Does anyone know how i can do this?

 

Regards,

Link to comment
https://forums.phpfreaks.com/topic/93720-auto-fill-in-form-php-help/
Share on other sites

You Should use a database to save yourself a lot of trouble down the road, but to do what u want make a file called comics.php and put this in it

<?php
$comics = array();
$comics[0]['Nane'] = "Larry";
$comics[0]['Age'] = 25;
$comics[0]['Phone'] = "555-555-5555";

$comics[1]['Name'] = "Mo";
$comics[1]['Age'] = 35;
$comics[1]['Phone'] = "555-555-5555";
?>

then links going to your bookme.php should change to bookme.php?comic=0  if it was coming from Larry's page

then in book me you add to the top

<?php
require_once('comics.php');
?>

Then in your form on bookme.php adjust the inputs to be like

<input type="text" name="Comic" value="<?php echo $comics[$_GET['comic']]['Name'];?>" />

Make sense

 

 

Then you could replace yuor 25 comic pages with 1 that is like

view_comic.php?comic=1

and then simply say

<?php
require_once('comics.php');
if(array_key_exists($_GET['comic'],$comics)){
$id = $_GET['comic']
#comic data

echo "Name: ".$comics[$id]['Name']."<br />";
echo "Phone: ".$comics[$id]['Phone']."<br />";
}
else{
echo "Error: Comic Not Found"
}
?>

 

This is why a database be helpful instead of doing a single array

Agreed, you should keep a central list of comedians. But if you don't want to do that, you can do this:

 

on John Doe's comedian's page:

<input type="button" value="Book Me" onclick="window.location.href='/bookme.php?comic=<?php echo urlencode("John Doe"); ?>';" />

This will generate HTML like this:

<input type="button" value="Book Me" onclick="window.location.href='/bookme.php?comic=John%20Doe';" />

 

on bookme.php:

Comedian: <input type="text" value="<?php echo htmlspecialchars($_GET['comic']); ?>" />

 

urlencode() and htmlspecialchars() escape/convert any special characters

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.