Jump to content

Running a function through html form


Drayen

Recommended Posts

Sorry if I'm wording this wrong, here's my problem:

 

The form:

 

<html>

<head>

<title>Product Update</title>

</head>

<body>

 

<form action="index.php" method="get">

Product: <input name="product" type="text" />

Starting Price: <input name="price" type="text" />

<br />

Description: <input name="description" type="text" />

<input type="submit">

</form>

 

</body>

</html>

 

Part of the php file:

 

function add()

{

 

$AAA = new AAA("Product", $_GET["product"], $_GET["price"], "images/unknown.jpg", $_GET["description"]);

 

echo '<img src="'. $AAA->GetPhoto() .'" align="left" />';

echo '<b>'. $AAA->GetName() .'</b>: '. $AAA->GetModel();

echo '<p>Starting from: '. $ipod->GetPrice() .'</p>';

echo '<p>'. $AAA->GetDescription() .'</p>';

}

 

Basically I don't want the fucntion add to execute unless it's being triggered by coming from the form page, so how would I go about doing this? Right now I just have the function add() above and it runs but that means it runs even when I'm not coming from the form site.  Any help would be appreciated.

Link to comment
Share on other sites

basically your check to see if the buttons been pressed, i updated the submit button with a name

<input type="submit" name="submit" value="submit">

we then check to see if that element has a value *button name* i called it submit..

 

<html>
<head>
<title>Product Update</title>
</head>
<body>

<?php
//this is the key to getting it to work
if(!empty($_GET['submit']))
{
add();
}

function add()
{

$AAA = new AAA("Product", $_GET["product"], $_GET["price"], "images/unknown.jpg", $_GET["description"]);

echo '<img src="'. $AAA->GetPhoto() .'" align="left" />';
echo ''. $AAA->GetName() .': '. $AAA->GetModel();
echo '<p>Starting from: '. $ipod->GetPrice() .'</p>';
echo '<p>'. $AAA->GetDescription() .'</p>';
}
?>

<form action="index.php" method="get">
Product: <input name="product" type="text" />
Starting Price: <input name="price" type="text" />


Description: <input name="description" type="text" />
<input type="submit" name="submit" value="submit">
</form>

</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.