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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

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.