How to check if form has NOT been submitted?

Discussion in 'PHP' started by dwest, Dec 27, 2006.

  1. #1
    I have this:

    If $content exists and form1 has been submitted then
    do something
    else if $content exists and form2 has been submitted then
    do something else
    else if $content exists
    do this.

    I would like this instead:

    if $content exists and no form has been submitted then
    do something
    If $content exists and form1 has been submitted then
    do something else
    else if $content exists and form2 has been submitted then
    do this.

    How do I check for "no form has been submitted"?

    Thanks!
     
    dwest, Dec 27, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    inside the forms use <input type="hidden" name="form" value="1"> for form one and <input type="hidden" name="form" value="2"> for form two, then
    switch($_POST['form'])
    {
    case "1":
    //form 1 submitted
    break;
    
    case "2":
    //form two submitted
    break;
    
    //optional below
    default:
    // no forms submitted
    break;
    }
    PHP:
     
    krakjoe, Dec 27, 2006 IP
  3. dwest

    dwest Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yep,
    I understand that but that's not what I was asking.
    I want to reverse the sequence so the default is first. Thus I have to have an additional parameter along with default since it is always present.

    Any ideas?
     
    dwest, Dec 27, 2006 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    
    if (!isset($_POST))
    
    
    PHP:
    ??
     
    nico_swd, Dec 27, 2006 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    I'm not sure I understand the question, so to answer :

    How do I check for "no form has been submitted"?

    if(!$_POST)
    {
    // no form submitted
    }

    sorry I just don't get it :S if u can think of a better explanation please post it ....or some actual code or the code ur trying to write that's needs fixing....
     
    krakjoe, Dec 27, 2006 IP
  6. tgo

    tgo Peon

    Messages:
    124
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Not sure if this will help, but the submit buttons you are using have a name and value pair that is sent along with the form entries and is blank if no form is submited.

    for form 1
    <Input type="submit" name="form" value="Continue">

    for form 2
    <Input type="submit" name="form" value="Go">

    I use asp not php so i cant give code but i check this way.

    <%
    if request.form("form") = "" then
    
    Else if request.form("form") = "Continue" then
    
    Else if  request.form("form") = "Go" then
    
    End if
    %>
    Code (markup):
    Hope this helps.
     
    tgo, Dec 27, 2006 IP
  7. dwest

    dwest Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks!
    if (!isset($_POST))
    That's what I need to know. :)
     
    dwest, Dec 27, 2006 IP
  8. dwest

    dwest Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    oooops!

    if(!$_POST) was actually what I needed.
    Thanks much to all!
     
    dwest, Dec 27, 2006 IP