I'm a newbie into programming php, and i'm compleatly stuck with my code. I hope I can explain my problem more accurate here.

With dynamic action I mean that the action attributte in the <FORM> tag should be able to send the user to different pages.

I've database which consists of several entries. My webpage lists these entries in a webpage with a checkbox after each entry. From this checkbox you are supposed to select the entry you would like to update,delete or view detailed information about.

Above the listning I've a menu with different choiches(update, delete...). These links are supposed to send the selected (checked values in an array) to a page wich process the data submitted. I'm not sure how this can be done by using this menu?

Problem : How can I make the form action field go to different pages based on my menu selection? I know this code have some missing parts 😕

I guess some of my problem here is passing variables from server-side scripting to klient side script(javascript). :rolleyes:
Code example:

[B]function menu(){
?>
<a href="search.php">Search</a>&nbsp;|&nbsp;	

<?php
     echo "<a href='delete.php' onClick='this.form.submit();'>Delete</a></span>&nbsp;|&nbsp;"
     echo "<a href='edit.php' onClick='this.form.submit();'>Edit</a></span>&nbsp;|&nbsp;"
.........
?><a href="logout.php">Logout</a>&nbsp;|&nbsp;
<?php
}

[B]function display_all_trans($result){[/B]
?>

<form name="form" action="" method="post"> 
<table class="formBoxStyle" width="95%" cellpadding="2" cellspacing="0">
<?php
$color = "#ffffff";
$num_results = $result->num_rows;
for ($i=0; $i<$num_results; $i++)
{
  $row = $result->fetch_assoc();
  if ($color == "#ffffff")
    $color = "#ccccff";
  else
     $color = "#ffffff";
  echo "<tr bgcolor='$color'><td>$row[id]."</td>";
  echo "<td>".$row[Fname]."</td>";
  echo "<td>".$row[Lname]."</td>";
  echo '<td><a href="mailto:'.$row[Email].'">'.$row[Email].'</td>';
  echo "<td><input type='checkbox' name='check[]' value='".$row[trans_id]."'></td>";
	echo "</tr>";

}
?></table>
</form>

What I try to achieve is that the check[] array is beeing passed along with the onClick attribute in the menu.

I've a main function that calls these functions pluss footer, header .....

Any help would be appreciated!

    Your question is not clear. I have no idea what you mean by 'action field'. Also, try to use the PHP formatting of this forum...it makes the code more readable.

      Thanks for your feedback.

      I've edited my question and I hope it's become more clear and readable for you.

      Best,

        I think I get it. You have a list of things from your database listed in a form (like email messages on hotmail or gmail) and when the user CHECKS them and clicks submit, you want to either EDIT, DELETE, etc. depending on what they have chosen in a SELECT box.

        You can either do javascript to handle it (which sounds complicated) or you can create a single PHP script that calls some function depending on what value the select box has. i'd go for the php solution because it doesn't depend on the user's browser even having javascript.

        suppose your form was like this:

        <form method="post" action="handler.php">
          <select name="cmd">
            <option>edit</option>
            <option>delete</option>
            <option>email</option>
            <option>serve with potatoes</option>
          </select>
        
        (list of items here)
        
          <input type="submit" name="submit" value="submit>
        </form>
        

        then your script could be like this:

        // *** HANDLER.PHP ***
        
        if (isset($_POST['submit'])) {
          switch($_POST['cmd']) {
            case 'edit':
              include('edit_include.php');
              break;
            case 'delete':
              include('delete_include.php');
              break;
            case 'email':
              include('email_include.php');
              break;
            case 'serve with potatoes':
              include('serve_with_potatoes_include.php');
              break;
            default:
            die('unrecognized cmd value');
          }
        } else {
          die ('no data submitted');
        }
        
        

        Then all you do is put your code in the various different files that you include such as edit_include.php

        does that make sense?

        Another way is that you put all the code in handler.php and divide it into functions then instead of:

        include('edit_include.php');

        you would:

        do_edit($_POST);
          12 days later

          Hi

          Thanks for your tips, they really helped me along! I can now make a solution that works, but do you know if there is any way of submiting the array values? e.g. with the eventhandler onClick() 😕 My idea is that I want a "text menu" with hyperlinks to pass along the array values.

          Maybe something like this??

          <a href="#" name="edit" onClick="handler.php">Edit</a>
          <a href="#" name ="delete" onClick="handler.php">>Delete</a>

          I would like to skip the submit button<Input type="submit"...>, and use my menu for this work.

          Is this possible, or is there any other solution for this.

          I would really appreciate some tips here 🙂

            if you don't mind using form buttons, you could do something like this:

            your form:

            <form method="post" action="handler.php">
            
            (list of items here)
            
              <input type="submit" name="cmd" value="edit">
              <input type="submit" name="cmd" value="delete">
              <input type="submit" name="cmd" value="email">
              <input type="submit" name="cmd" value="serve with potatoes">
            </form>
            

            then handler - i changed the name attribute of the submit buttons to 'cmd' so you need to change the first if statement:

            // *** HANDLER.PHP ***
            
            if (isset($_POST['cmd'])) {
              switch($_POST['cmd']) {
                case 'edit':
                  include('edit_include.php');
                  break;
                case 'delete':
                  include('delete_include.php');
                  break;
                case 'email':
                  include('email_include.php');
                  break;
                case 'serve with potatoes':
                  include('serve_with_potatoes_include.php');
                  break;
                default:
                die('unrecognized cmd value');
              }
            } else {
              die ('no data submitted');
            } 

            If you want to use images instead of form buttons, use type='image' for the submit buttons:

            <input type="image" name="cmd" value="edit" src="images/edit_button.gif">

            If you area really dead set on using <a> tags for the form, you'll need to alter your form, giving it a name and a hidden input named 'cmd' instead of submit buttons.

            <form method="post" action="handler.php" name="my_form">
            
            (list of items here)
            
              <input type="hidden" name="cmd" value="">
            </form>
            

            and your links will need to trigger a bit of javascript:

            <a href="" onClick="document.forms['my_form'].cmd.value='edit';document.forms['my_form'].submit();">edit</a>

            or something like that....i'm no javascript pro so if it doesn't work you'll need to maybe post the clientside scripting forum here or google around or something.

            EDIT: i posted this but the site ate the javascript...the <a> tag should contain this:

            <a href="" onClick="document.forms['my_form'].cmd.value='edit';document.forms['my_form'].submit();">

              Thanks for your quick reply last time! 🙂

              I tried to implement your solution but this did not work for me(HTTP 403 Forbidden). I've googled around to find an answer but the only thing I came up with was problems with browsing directories. I tried your solution locally(IIS) and on my another web sever running Apache with the same result. Any clue?

              Comment I found on the Internet:
              "This is because our Web site deliberately does not want you to browse directories - you have to navigate from one specific Web page to another using the hyperlinks in those Web pages. "

              You quoted this last time:

              <a href="" onClick="document.forms['my_form'].cmd.value='edit';document.forms['my_form'].submit();">edit</a> 

              EDIT: i posted this but the site ate the javascript...the <a> tag should contain this:

              <a href="" onClick="document.forms['my_form'].cmd.value='edit';document.forms['my_form'].submit();">

              I can't see any difference between these two? 😕 Was they supposed to be alike?

              I would appreciate your help! 🙂

                the 2nd time i posted, it displayed properly both times. there is no difference.

                403 error means your web server is trying to load a page it is not permitted to load. this could be due to the wrong value for 'action' in your form tag (either the page doesn't exist or it is one the wrong file permissions on it). Do you have a file called 'handler.php'?

                Or the problem could be your include statements. Web servers will refuse to serve files sometimes depending on how they are configured and who 'owns' the file requested.

                the other possibility are the include statements. you have to write those files to handle the edit/delete/serve with potatoes functions. have you created them yet?

                  Write a Reply...