Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-09
9
Medium Priority
?
287 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 84

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 84

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 84

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 84

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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

877 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