Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

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

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

how to put my own form (formular) on webpage


Reply


6 Posts   3042 Views

Avatar
widoczni.pl

Community Member, 9 Posts

13 March 2008 at 1:37pm

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>
------------^

Avatar
Willr

Forum Moderator, 5513 Posts

13 March 2008 at 8:53pm

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.

Avatar
widoczni.pl

Community Member, 9 Posts

14 March 2008 at 1:48am

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.

Avatar
Willr

Forum Moderator, 5513 Posts

14 March 2008 at 9:26am

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.

Avatar
ScottiouS

Community Member, 54 Posts

9 April 2008 at 2:39pm

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!

Avatar
ScottiouS

Community Member, 54 Posts

9 April 2008 at 4:34pm

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!