2

I have a node/content that outputs like a form that is available to guests to add jobs to. I would like to implement this HTML inside of the form to reduce spam:

<div style="POSITION: absolute; TOP: -1000px; LEFT: -1000px">
    <label for="address">If you see this, Leave Empty:</label>
        <input id="address" name="address" />
</div>
<div style="display: none;">
    <label for="username">If you see this, Leave Blank:</label>
        <input id="username" name="username" />
</div>

I kind of need this within the <form> tag.

Now when the form gets submitted, I'd like to be able to check for this and be sure both inputs are empty, and if they are empty, the form should be submitted, otherwise, if either is filled in with anything, it should not be allowed to be submitted. I did this on another, Non-Drupal, site and it eliminated the SPAM on that form completely. But now I'm on a Drupal site, and would like to understand how to do this via a node.

I don't currently have FTP Access, however, I do have complete Admin Access on the Drupal site, so if there is a way to do this via Drupal that would be preferable. Is there a module that will do something similar to this that I can add as a field on that node?

Any help to point me in the right direction on getting started for this is greatly appreciated. Also, I have the Devel Module installed if that helps...

6
  • 1
    If you don't have FTP access, you are doomed anyway. regain it as soon as possible. Maybe there are contrib modules to do that, but if you can install them, you can as well install your own...
    – Mołot
    Commented Dec 12, 2013 at 20:12
  • Molot is above is right, you'll need FTP access to do anything. Are you just trying to add a honeypot field to your form? If so (and you have FTP access) the honeypot module does what you're looking to do already - drupal.org/project/honeypot Commented Dec 12, 2013 at 20:19
  • Honey Pot field is already installed on the form, so it's no good. Form is still getting spammed to death! The solution above works for me and never had problems with it. Commented Dec 12, 2013 at 20:21
  • @Mołot - Yeah, I definitely need to get FTP access... so it's kind of shaky doing anything on the site without it. Commented Dec 12, 2013 at 20:23
  • @Mołot It is possible to get modules downloaded through the UI. Shared (read: insecure) hosting often gives the Drupal user write access to the whole web root, and you can simply pop the URL in, or even upload a module from local, at admin/modules/install
    – Clive
    Commented Dec 12, 2013 at 21:27

1 Answer 1

4

Create own helper module. Use hook_form_alter(), specifically hook_form_node_form_alter() variant. In it, just add #markup element.

$form['my_markup'] = array(
  '#markup' => "Your HTML here",
);

But in content of your question, it seems you want more than own html. It looks like you want to add some active elements. So see Form API Reference for elements you need. To process values, you will need to define submit handlers.

2
  • hmmm, so I am lost now. You are not speaking my language I suppose. How am I supposed to use hook_form_node_form_alter? I don't know even how to create a helper module. Should I just run the php code in Devel? Commented Dec 12, 2013 at 20:35
  • @SolomonClosson See this intro documentation to Drupal 7 modules - it is absolute must-read for new Drupal developers.
    – Mołot
    Commented Dec 12, 2013 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.