sNews Forum

sNews 1.7 (current stable version) => General questions => Topic started by: sibas on February 23, 2013, 07:18:06 pm

Title: How can I add multiple forms in one?
Post by: sibas on February 23, 2013, 07:18:06 pm
Hi there, I have stuck with the following!
I have 2 different forms to search names, and cities, so except the function search() I have function search_names() and function search_city()

Now my problem is that I don't want to have 3 different forms and I don't want to use ajax, I want to have one and with some option stuff to change to the right function.

Is there any idea how to make work this!
Title: Re: How can I add multiple forms in one?
Post by: philmoz on February 24, 2013, 01:22:30 pm
Set form up with radio buttons.
One for names.
One for city.
(obviously a field for your search query is also required)

When form entered, use the activated radio to direct search query to the relevant function.
Title: Re: How can I add multiple forms in one?
Post by: sibas on March 01, 2013, 06:02:40 pm
Hey philmoz thanks for your answer
finally I decided to use those forms in 3 different pages  :)
Title: Re: How can I add multiple forms in one?
Post by: dirtyjokesfunny on September 29, 2018, 09:50:09 am
Simplest way is to give each submit button a unique name. Then check if it was submitted, and process accordingly.

    <form id="form_1" action="" method="post">
        <input type="submit" name="submit_1" value="Submit" />
    </form>

    <form id="form_2" action="" method="post">
        <input type="submit" name="submit_2" value="Submit" />
    </form>


<?php

if( $_POST['submit_1'] ) {

    // Do stuff

}
else if( $_POST['submit_2'] ) {

  // Do stuff

}

?>
It's a bit hackish, but will do exactly what you need it to.