Jump to content

Adding a custom ph form and processing to Drupal


mapleleaf

Recommended Posts

I have just opened up Drupal and need to add a form that gets processed to one of the existing pages. All the form layout and processing are ready. I just need some help in how one fits this into Drupal. Custom theme? New page template? Seems too much php to add as a PHP snippet in the page editor.

Any thoughts much appreciated.

Link to comment
Share on other sites

You can do it the drupal way or you can do it your own way.  I've found that doing anything with drupal's forms requires learning.  If you have the views module installed you can create a new view, or hack your template and add a menu path and include a template file with your PHP code, or just make a "form.php" file and process your own forms.

 

Drupal usually has jquery built in with Ajax support, but you can grab the jquery.form plugin and use Ajax Forms and then post to your own form.php. 

 

From there, I do a bootstrap and then map your $node->filed = $_POST['value'];  and do a node_save($node);  and then display a message to the user.

 

 

Link to comment
Share on other sites

one thing to note is that if you're bootstrapping a file in drupal, you should put the file at the same root path as your index.php - otherwise you'll have bootstrap nightmares.

 

For example:

 

public_html/index.php

public_html/forms.php

 

Inside forms.php

 

set_include_path($_SERVER['DOCUMENT_ROOT']);
require_once $_SERVER['DOCUMENT_ROOT'].'/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

 

And now you have full access to drupal's database layers, user authentication, and all of drupal's classes and modules.  You can process your form and save the data into an object and node_save that object.  There's also node_submit and a few other functions for validation. I recommend http://drupal.org for more on that stuff.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.