1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP and forms

Discussion in 'PHP' started by gilgil2, Apr 29, 2012.

  1. #1
    Hi, I am trying to create a page where depending on which one of three radio buttons is selected something different happens. The context is that users have already registered and so the 'gigname' is taken from url (which seems to work now).The original url looks like example.com/listtype.php?name=gigname (with the correct gigname appearing).However instead of doing what it is supposed after submit the url just changes to example.com/listtype.php?type=(and in here the value appears from the chosen radio button).I do not know what is going wrong so any help would be appreciated, here is the code:
    • <?
    • $gigname = $_GET['name'];
    • ?>
    • <form>
    • Listing type: <input type="radio" name="type" value="free">Free<br>
    • <input type="radio" name="type" value="premium">Premium<br>
    • <input type="radio" name="type" value="featured">Featured<br>
    • <input type="submit" />
    • </form>
    • <?
    • if(isset($submit) && isset($free))
    • {
    • header ("Location: http://www.example.com/gig.php?name=' . $gigname . '");
    • }
    • elseif(isset($submit) && isset($premium))
    • {
    • echo 'do something else';
    • }
    • elseif(isset($submit) && isset($featured))
    • {
    • echo 'do another thing';
    • }
    • elseif(isset($submit) && !isset($free) && !isset($premium) && !isset($featured)) {
    • echo 'please make a selection';
    • }
    • ?>
    Thanks in advance

     
    gilgil2, Apr 29, 2012 IP
  2. t-pack25

    t-pack25 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    it's no good way. your varios is <inputtype="radio"name="type"value="free">Free<br>
    so you must use condition
    if($type == 'free') ...
     
    t-pack25, Apr 29, 2012 IP
  3. fixesign

    fixesign Member

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    Some cases simply because a single or double quotes. try it:
    header ("Location: http://www.example.com/gig.php?name=" . $gigname );
     
    fixesign, Apr 29, 2012 IP
  4. SoftCloud

    SoftCloud Well-Known Member

    Messages:
    1,060
    Likes Received:
    28
    Best Answers:
    2
    Trophy Points:
    120
    #4
    Is this what you're after?

    <?php
    $gigname = $_GET['name'];
    ?>
    <form method="POST">
    Listing type: <input type="radio" name="type" value="free">Free<br>
    <input type="radio" name="type" value="premium">Premium<br>
    <input type="radio" name="type" value="featured">Featured<br>
    <input type="submit"/>
    </form>
    <?php
    if(isset($_POST['type'])) {
    	switch($_POST['type']) {
    		case "free":
    			header("Location: http://www.example.com/gig.php?name=" . $gigname);
    		break;
    
    		case "premium":
    			echo "Something for the premium members";
    		break;
    
    		case "featured":
    			echo "Something for the featured members";
    		break;
    
    		default:
    			echo "Please make a selection";
    		break;
    	}
    }
    ?>
    PHP:
     
    SoftCloud, Apr 29, 2012 IP
  5. alfa_375

    alfa_375 Active Member

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #5
    very clean code softCloud.
     
    alfa_375, Apr 30, 2012 IP
  6. Raja sekar12

    Raja sekar12 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <html>
    <body>

    Welcome <?php echo $_POST["fname"]; ?>!<br />
    You are <?php echo $_POST["age"]; ?> years old.

    </body>
    </html>this is also wen design and development company in chennai. for more information visit chennaipixel
     
    Raja sekar12, Apr 30, 2012 IP
  7. ranaji

    ranaji Peon

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    make a connention page then another page name form then through ajax do that. for more help please go to http://phproots.com.
     
    ranaji, May 3, 2012 IP
  8. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #8
    radio buttons in the same form field will come as arrays()
    Easiest way to do this is to use AJAX and the onChange feature to grab the PHP handler file and run your script that way.
    This way theres no radio button SUBMIT necessary since it changes as you click it. In this method you can use buttons, and anything else you want other than being limited to radio button.

    IM me if you want AJAX method, I create and sell them in all forms and AJAX engine forms. with PHP handlers, and all of them are customize-able. Once you use AJAX and PHP combo, you'll never go back to page reloads and submission forms with their limitations and annoying clicking/clacking page reloading. Oh yeah, and without spam you can also see what Im referring to , down lower in my sig.
     
    ezprint2008, May 4, 2012 IP