Solved

can I have a form that posts to itself within a function

Posted on 2011-03-09
9
282 Views
Last Modified: 2012-05-11
public function viewProductFolder($folderid) {

<form action="products.php?a=vpf&fid='.$folderid.'" method="POST" id="archiveform">

<input type="submit" value="save form">
</form>
}

when I press submit I am taken to the correct url, but there is no data on the page

can I have a form that posts to itself within a function
0
Comment
Question by:rgb192
  • 4
  • 4
9 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 35085722
You can but you have to re-write the data to the form or page yourself.  It won't be automatic.
0
 

Author Comment

by:rgb192
ID: 35085769
how... and where
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 35085895
Here is a simple demo.  If you enter your name and class in lower case, you will see it posted in uppercase when you click on submit.  I did that so I could tell that it was being submitted.
<?php
$std_id = "Your Name"; 
$std_cls = "Your Class";
$age = "Age";
$gender = "Gender"; 

if(isset($_POST['submit'])) {
		$std_id = strtoupper($_POST['student']); 
		$std_cls = strtoupper($_POST['class']);
		$age = $_POST['age'];
		$gender = $_POST['gender']; 
		}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Form1</title>
</head>
<body>
<h1>First Form</h1>
<h3>Form info:</h3>
<form action="formFx.php" method="post">
Student: <input type="text" name="student" value="<?php echo $std_id; ?>" /><br />
Class:   <input type="text" name="class" value="<?php echo $std_cls; ?>" /><br />
Age:     <input type="text" name="age" value="<?php echo $age; ?>" /><br />
Gender:  <input type="text" name="gender" value="<?php echo $gender; ?>" /><br />
</pre>
<input type="submit" name="submit" value="Submit" />

</form>
</body>
</html>

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rgb192
ID: 35086007
I understand your example (form that posts to iteself)

but I dont understand what you mean

>>You can but you have to re-write the data to the form or page yourself.  It won't be automatic.

a form within a function


maybe
if(isset($_POST['submit'])) {
repeat form again
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 35086173
You said "when I press submit I am taken to the correct url, but there is no data on the page".  I showed you how to put data on the page which you apparently already understand.  And "can I have a form that posts to itself within a function".  Posting to itself is easy but if you want to include it in a function, you do have to add the logic to do that and it has to be on the next page.  If you were inserting variables in the form function above, you just have to get them from the POST variables like I did.
0
 

Author Comment

by:rgb192
ID: 35086450
the page recreates itself when I go to
products.php?a=vpf&fid=43

but when I press submit
the page goes to
products.php?a=vpf&fid=43

but it is a blank page
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 35086619
You need to look at your control statements like 'if' and 'case' to see what is blocking it.  Look at the code where you function is being called.
0
 
LVL 5

Accepted Solution

by:
onemadeye earned 500 total points
ID: 35086668
Perhaps empty the form action to :
<form action="" method="POST" id="archiveform">

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 35124826
took out the id and it works
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question