Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Using Form Actions not working?

edited July 2012 in Vanilla 2.0 - 2.8

this is using the CustomPage plugin.

is this possible to use a POST form action to another custom page to a PHP page, it just sits on the inital Page and dosen't react to a button click at all.

Using this:

<

form id="form1" name="form1" method="post" action="Content/Results.php">
or

<

form id="form1" name="form1" method="post" action="Content/Results">

dosen't seem to be working. any idea

Tagged:

Comments

  • @PinkSheep If do you have a button within your forum to click on? Also, was the newline after the opening angle bracket on purpose? That could confuse the browser. Also, the action URL is relative to the current URL in the browser. For example: if the address bar in your browser reads, http://mywebsite.com/custompage.php?page=pg1 then your form would try to send your browser to http://mywebsite.com/Content/Results.php

    Hope that helps, and please let me know whether the double new line after the angle bracket that opens the HTML tag was on purpose.

  • i just copied the top line of the html form section, i've got it working now. i was having a stupid moment. i forgot to place them just in the PAGES folder also the double line thing was a pasting error.

  • You need to read up on and MCV (Model, Controller, View)

    You don't post directly to views, this is not how a well structured application works, these days.

    Secondly I would look into the form builders, it should make life easier.

    <?php
    echo $this->Form->Open(array('action'=>Url('plugin/page/results',true));
    ....
    echo $this->Form->TextBox('MyField');
    echo $this->Form->Button('Submit');
    echo $this->Form->Close();
    

    then you can get results back

    <?php
    if($this->Form->IsPostBack() != False){
        echo Gdn_Format::Text($Sender->Form->GetFormValue('MyField'));
    }
    

    Generally view aren't the right place for a lot of logic, but I presume you are doing something simple.

    Remember to be safe, don't allow unsanitized content to be outputed.

    grep is your friend.

  • Thanks x00, i'm very new to web development i'm primary based in c#, C++ .NET etc. thanks for the advice i shall look into MCV

  • I am having the same problem. When I try to submit nothing happens

    <?php if (!defined('APPLICATION')) exit(); 
    
    
        // only execute if postback
    
    
                $Session = Gdn::Session();
                if ($Session->IsValid()) {
                $userid = $Session->UserID;
                $Name = $Session->User->Name; }
    
                $con = mysql_connect("","","");
    
                mysql_select_db("ourplayb_vnl1", $con) or die(mysql_error());
    
                $result = mysql_query("SELECT Email FROM GDN_User 
                WHERE Name='$Name'");
    
                if (!$result) {
                    $message  = 'Invalid query: ' . mysql_error() . "\n";
                    $message .= 'Whole query: ' . $query;
                    die($message);
                }
    
                    $row = mysql_fetch_assoc($result);
                    var_dump($row); // see what type of variable mysql_fetch_array() gave you
                    $Email2 = $row['Email'];  // ...and use that knowledge here
    
    if($_SERVER['REQUEST_METHOD'] == 'POST')
    {
    
    
                $sql="INSERT INTO KhanKon2012 (email, username, GameSession1, GameSession2, GameSession3, GameSession4)
                VALUES ('$Email2','$Name','$_POST[GameSession1]','$_POST[GameSession2]','$_POST[GameSession3]','$_POST[GameSession4]')";
    
                if (!mysql_query($sql,$con))
                    {
                    die('Error: ' . mysql_error());
                    }
            echo "1 record added";
    
    mysql_close($con);
    }
    
    ?>
    
    
    <p>Pleas pick which events at the CON you would like to attend.</p>
    
    <h1>Saturday</h2>
    
    <form method="post" action="<?php echo $PHP_SELF;?>">
    <select name="GameSession1">
        <option value="battlestar">Battlestar Galactica</option>
        <option value="vampire">Vampire Red Dawn (GM: Francis)</option>
        <option value="something">Something else</option>
    </select>
    
    
    <select name="GameSession2">
        <option value="battlestar">Battlestar Galactica</option>
        <option value="vampire">Vampire Red Dawn (GM: Francis)</option>
        <option value="something">Something else</option>
    </select>
    
    
    
    <select name="GameSession3">
        <option value="battlestar">Battlestar Galactica</option>
        <option value="vampire">Vampire Red Dawn (GM: Francis)</option>
        <option value="something">Something else</option>
    </select>
    </form>
    
    
    
    <h1>Sunday</h2>
    <select name="GameSession4">
        <option value="battlestar">Battlestar Galactica</option>
        <option value="vampire">Vampire Red Dawn (GM: Francis)</option>
        <option value="something">Something else</option>
    </select>
    <input type="submit" value="submit" name="submit_button" />
    
    </form>
    

    Can somebody help me figure out what kind of idiocy I am doing?

  • If you follow the advice given by x00 and try to restructure under that framework, you may be able to solve your form issues easier.

    http://vanillaforums.org/discussion/comment/164208/#Comment_164208

    and the forms docs here, and possibly more info on wiki
    http://vanillaforums.org/docs/models

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.