IF THEN for button?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Is it possible in PHP to do the following?

I've got a php page with a form, that form has radio buttons group and
an option group list.  It also have a button, Continue.

When the continue button is presed I want it to look at: this:
If Radiobutton1 is pressed and option group lsteditorial is selected,
goto write-editorial.php
if Radiobutton1 is pressed and option group lstpres is selected, goto

and etc... for other combinations,  so based on the selections of the
radio buttons and option groups goto a specific page:

here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
<html xmlns="http://www.w3.org/1999/xhtml ">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Production Report</title><style type="text/css">
.style2 {font-size: 24px}
.style5 {font-size: 18px}

  <p><img src="http://info/test/etnlogored2.gif" width="199"
height="30" /></p>
  <p><em><strong><span class="style2 style5">What would you like to
  <form id="form1" name="form1" method="post" action="select.php">
        <input type="radio" name="radReadWrite" value="1"
id="radReadWrite_0" />
        <span class="style5">Write Report</span></label>
      <br />
        <input type="radio" name="radReadWrite" value="2"
id="radReadWrite_1" />
        <span class="style5">View Report</span></label>
    <p><em><strong><span class="style5">Please also select the
      <select name="lstdepartment" id="lstdepartment">
        <option value="lstEditorial">Editorial</option>
        <option value="lstPrepress">Pre Press</option>
        <option value="lstInformationTechnology">Information
        <option value="lstPres">Press</option>
        <option value="lstMailroom">Mail Room</option>
        <option value="lstCirculation">Circulation</option>
      <input type="submit" name="btnSubmit" id="btnSubmit"
value="Continue" />
      <br />

thanks for any help as to the code or where to put it so it works with
the button.

Re: IF THEN for button?

paul814@excite.com wrote:
Quoted text here. Click to load it

If you do this in php alone you have to submit what you pressed and then  
go to  yet another page after analsying it all.

This seems to be to be a case for javascript.

Re: IF THEN for button?

On Nov 15, 1:20 pm, paul...@excite.com wrote:
Quoted text here. Click to load it

Look at the header() function.

Re: IF THEN for button?

paul814@excite.com wrote:
Quoted text here. Click to load it


The first thing to remember is that PHP code is all executed before the  
page is sent to the browser.  You have no direct interaction with the  
PHP code; all you can do is submit HTML requests (i.e. GET, POST) to the  
server and have that execute the code.

So, with this in mind, in your select.php (the target for your form),  
your $_POST array will have an element with the index 'radReadWrite' (if  
a button is selected).  This will contain 1 or 2, depending on the radio  
button selected.

It will also contain an element with the index 'lstdepartment' for your  
SELECT box, and value of the element will be the value of the option.

Based on these values, determine which page you want to go to, and use  
the header() function to redirect the browser to the page you wish.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: IF THEN for button?

In our last episode,
lovely and talented paul814@excite.com broadcast on comp.lang.php:

Quoted text here. Click to load it

HTML cannot do this.  Once you have served your page, it is HTML and php has
nothing more to do with it.  You can use client-side scripting to
accomplish something like what you want.  You cannot have one set of radio
buttons with different actions because to get different actions, they would
have to belong to different forms.  What you can do is have the one action
(select.php) generate different pages according to the radio button and
other controls.

Or to put it another way:  HTML is markup.  It is not a programming
language.  It has no conditionals.  If you want conditions you have
implement them with client-side scripting or server-side scripting;
but you cannot do it with HTML.   An HTML form can only "goto" one place:
the url given for the action attribute.  Client-side scripting can alter
that goto according to conditions, or server-side you can generate different
documents to return based on the POST or GET data, but in that case you get
the different returns when "goto" the one handler given in the action

This would be abundantly clear if you learned HTML before trying to get php
to generate HTML for you.

Lars Eighner     <http://larseighner.com/ <http://myspace.com/larseighner
                         Countdown: 432 days to go.
                    What do you do when you're debranded?

Re: IF THEN for button? (HTML Post)

Quoted text here. Click to load it

This is how I would do it:

    switch ("on"){
        case $_POST["RadioButton1"]:
            if($_POST["1stpres"] =3D "checked"){
                echo =
        case $_POST["RadioButton2"]:
            //doit again
} else {
    // Display HTML FORM.

I should probably point out that "option group" was probably the wrong =
phrase to use here.
HTML Select's have something called option groups, but you didn't use =
them here.
You just used straight-options.

Re: IF THEN for button?

On Nov 15, 1:20 pm, paul...@excite.com wrote:
Quoted text here. Click to load it

Paul, without a doubt, you should be doing this with JavaScript.

If you need any help with the code, let me know.


Site Timeline