Jump to content

Form idea but can it be done?


EchoFool

Recommended Posts

I have a form with 2 options, one is update, and one is report.

 

Now if the button to report is pressed the action of the form needs to go to report page. Where as if the update button is pressed the action should not header to a different page for it should just stay on the current page and "update" the information.

 

How ever i do not know how this can be done.

 

If I put an action in the form entities then it will always header away so i need it only go to the action when one of the buttons is pressed. One of the unfortionutly things is i cannot use 2 separate forms as i have just found out before they are post $_POST-ing the same text area. And if i put the text area in both forms it will display on the web page twice which is not good .

 

The only idea i can think of but i do not know if it will work is something like this:

 

|<form1 - headers to filereport.php>

|

|<form2 - stays on the same page but just "refreshes" to allow the script to update>

|

| <button2>

|

|</form2>

|

|<button1>

|

|</form1>

 

Link to comment
https://forums.phpfreaks.com/topic/90370-form-idea-but-can-it-be-done/
Share on other sites

It's pretty simple really, try this:

 

File Name: index.php

<?php

if(isset($_POST['report'])) {

header("Location: report.php"); // Put your location file here

} else if (isset($_POST['update'])) {

// Put your MySQL update query here or whatever you're wanting to update

}

?>

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

<!-- Form elements here -->

<input type="submit" name="report"> <input type="submit" name="update">

</form>

 

I think that's pretty much what you're trying to do.

Kinda except i can't use headers. Because the script is surrounded by 2 css files:

 

include css1.css

 

//script

 

include css2.css

 

 

 

This is because my site's content is always in the center div so i put the left right header and footer in my includes. And so as you would expect when i use a header i get the output already started. It is a pain!

How about this...

 

<?php

if(isset($_POST['report'])) {

echo "<meta http-equiv=\"REFRESH\" content=\"0;url=report.php\">"; // Put your location file here
exit;

} else if (isset($_POST['update'])) {

// Put your MySQL update query here or whatever you're wanting to update

}

?>

First, you really shouldn't separate CSS blocks with code.

 

Second, you can not put one form inside another.

 

Learn proper HTML before attempting to use PHP and you will find that you will write better PHP.

 

You don't need to go to different pages for this:

 

<?php
if (isset($_POST['submit'])) {
  switch ($_POST['submit']) {
      case 'Update':
//
//   update code here
//
         break;
      case 'Report':
//
//     report code here
//
         break;
    }
}
?>
<html>
<head>
CSS links here
</head>
<body>
<form method="post"> 
... form stuff ...
<input type="submit" name="submit" value="Update">
<input type="submit" name="submit" value="Report">
</form>
</body>
</html>

 

Ken

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.