Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » how to put my own form (formular) on webpage

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2931 Views
  • widoczni.pl
    Avatar
    Community Member
    9 Posts

    how to put my own form (formular) on webpage Link to this post

    I'd like to put in the source of the content page my own form for example:
    <form action="my_script.php" method="post" name="name" id="name">
    <input type="company_name" name="textfield">
    </form>

    This form will run my_script.php. The script should process variables sended by post (in this example company_name variable), then give some results (from my own databases) and put it back one the webpage.

    How to do it, cause now I have SS parsing error (cant parse form tag):
    </form>
    ------------^

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: how to put my own form (formular) on webpage Link to this post

    you might want to read up on SilverStripe forms - http://doc.silverstripe.com/doku.php?id=tutorial:3-forms. The second part of that - the browser poll you should be able to use/adapt that.

  • widoczni.pl
    Avatar
    Community Member
    9 Posts

    Re: how to put my own form (formular) on webpage Link to this post

    thanks for support. I've read it.

    But the problem is, how to run my own script which will access my own database (from my other application) and give back results on silverstripe page.

    could You help me with short instruction.

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: how to put my own form (formular) on webpage Link to this post

    right so using the the tutorial code as a template.. theres 2 PHP functions 1- BrowserPollForm() this is the function to output the form so this will be where you add your text fields and submit buttons etc... The second function doBrowserPoll() is much more interesting. This method is what is called when people submit the form.

    So I don't know what your my_script.php file does but if you copy the code from that into the doBrowserPoll() function (replacing variables etc etc) and use that method to connect to your database and process the form / do whatever you want.

    If you post some code someone might be able to look into it for you.

  • ScottiouS
    Avatar
    Community Member
    54 Posts

    Re: how to put my own form (formular) on webpage Link to this post

    I'm also curious about this.. I need to submit a form to an external site for processing. I cannot get the code from the remote location as it's a third party processor.

    So in short I would love the ability to customise the action tag of the <form> tag. I realise that this may be accomplished with javascript on the user end, but this does not work for two reasons:

    1) The odd chance that the user does not have js enabled.
    2) That I already have a script rewriting the action tag (also third party js!)

    Thanks for any help!

  • ScottiouS
    Avatar
    Community Member
    54 Posts

    Re: how to put my own form (formular) on webpage Link to this post

    Thanks to simon_w in the SS chat room i've fixed my problem.

    Simply sub class the Form class like so and replace the FormAction function with what you want in the action attribute:

    class extForm extends Form {
       function init() {
          parent::init();
       }
       function FormAction() {
          return 'http://www.myexternalsite.com/processes-tha-forms';
       }
    }

    Then reference the new form like so

    return new extForm($this, 'extContactForm', $fields, $actions, $validator);

    Thanks simon!

    2931 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.