Jump to content

form with multiple buttons


BluwAngel

Recommended Posts

If these are two submit buttons, you can check for the value being set to determine which button was clicked and act accordingly.

 

<form>
    <input type='submit' value='yes' />
    <input type='submit' value='no' />
</form>

 

receiving page

 

if(isset($_POST['yes']))
{
//do stuff
}
else if(isset($_POST['no']))
{
//do stuff
}

If these are two submit buttons, you can check for the value being set to determine which button was clicked and act accordingly.

 

<form>
    <input type='submit' value='yes' />
    <input type='submit' value='no' />
</form>

 

receiving page

 

if(isset($_POST['yes']))
{
//do stuff
}
else if(isset($_POST['no']))
{
//do stuff
}

 

Not quite. A value of a field is not passed as an index in the POST data. In the above, you would also need to set the Names to "yes" and "no" for that PHP logic to work. Or, you need to give your two submit buttons a name and then set the values accordingly.

 

    <input type="submit" name="response" value="Yes" />
    <input type="submit" name="response" value="No" />

 

if(isset($_POST['response']) && $_POST['response']=="Yes")
{
    //Yes response
}
else
{
    //Assume no response
}

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.