Posted by jweinraub on April 25, 2006 at 7:43pm
i am making a mail form, pretty much its a dropdown list with multiple names, where a user can choose who tos end the email to, a small msg box, and off it goes. no need for from/subject, etc. however, i like to have this in a node, so it selfsubmits rather than use a php page outside of drupal. i like for slight error checking, so it makes sure a name was selected, and there is a message > 5 chars.
so far, i got this, and it doesnt work:
Fill out a <em>brief</em> message in the box bellow and hit the send button. Sales leads should be sent via the Salesmap. Remember, the sales person has no way of knowing who sent the message unless you include your name.
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="frmMail" id="frmMail">
<p>
<h4>To:</h4>
<select name="optSalesman" id="optSalesman">
<option></option>
<option value="jon@com">Jon</option>
...
</select>
<br />
<h4>Message:</h4>
<textarea name="txtMsg" cols="30" rows="10" id="txtMsg"></textarea>
<br />
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
<?php
if ( $_POST['frmMail'] )
{
$to = $_POST['optSalesman'];
$msg = $_POST['txtMsg'];
$headers = "From: Intranet <root@com>\r\n";
$ret = mail($to,"MSG",$msg,$headers);
if ($ret)
echo "<h2>Success!</h2>";
else
echo "<h2>Failure!</h2";
}
?>its basic i know and not muich implemented yet, but im just testing as i go on..
Comments
Why not use the contact
Why not use the contact forms? (http://drupal.org/handbook/modules/contact)
They already do this.
You can put php snippets into nodes, but I would avoid it for anything other than displaying information. It is much better to write a module:
http://drupal.org/node/508
White Paper Designs
White Paper Designs
hmm
i figured a module would be the way to go, but pretty much, a subject and from is unnecessary for my needs.
all i need is a To: with a dropdown of pre-determined names, and a msg field for a short note, and thats it.
how can this be done?
i should also add that this is on our corporate intranet, nobody will be logged in, so this will be for anonymous usage. i just have a seperate list of 6 people that need to be emailed from within the company that reside outside of headquarters. this will then be texted to their mobile phones. the email address is an alias for their cell.
I would start with the
I would start with the contact module and modify for your needs.
For the drop down list, I would create the users with the a certain role. Then select all the users with that role to file the drop down box.
That way, you can update the drop down list by creating more/less users.
You can add a profile field for the user to add their phone-email address.
The module developer's guide is a good start: http://drupal.org/node/508
White Paper Designs
White Paper Designs
okay...
but, these people, nor anyone in the company will be logging into the drupal system. i have drupal installed on a corporate intranet where if people need to send a text message to the sales people, they just select whom, write the short message, and send. i feel contact based what i see isnt what i need.
on the contact node, it will just have
To: DROPDOWN - the first option should be blank so the first one wont get messages accidently, and an error should be generated if the blank one is still chosen
Message: TEXTAREA - this should contain the message, i think it should contain a minimum of 5 characters, anycase someone sends accidently too soon (texts cost money fter all)
Submit Button - well after it submits, it checks for errors, if all okay, it sends, otherwise a notice on the page will display.
i am not sure if contact is the best option for this as i dont want profiles and the only account on the system is mine, the admin.
i just want a form on the page so i really dont know how to get this implemented, from a drupal point of view. i rather not use an action from outside php script..
thnx again
What is the question?
The contact module creates a form and sends an email. That is exactly want you want to do. Just get rid of the extra functionality.
I was just suggesting using the profiles as any easy way of storing information about the people you want to text message. Those profiles do not have to be public. The contact module provides a per-user and a site-wide contact form. Use the site-wide code and get rid of/turn off the per-user version.
This is a straight forward piece of code. There is a learning curve associated with learning the 'drupal-way', but after that it is not too hard.
If you do not want to learn how write drupal code then pay some else to:
ttp://drupal.org/forum/51
White Paper Designs
White Paper Designs
ok
but how do i put the form itself into a node? or do i need to do it in a different fashion. i am new to drupal. i know php well enough to get by to do basic stuff but nothing major (like making a CMS for example)..
i have a page, at http://intranet/text-messaging where i have a form as the text (using php option).
thanks for your help and being so patient with me..
It looks like you got it
It looks like you got it working.
Just FYI...
You can paste code into a node, but this approach is hard to maintain and does ignores many of the drupal features.
I never put PHP code into a node because if you make a typo then you can end up with code you can not edit. Then you have to go into the database to try and fix or delete the node.
Good luck.
White Paper Designs
White Paper Designs
for our needs it seems to do
for our needs it seems to do the trick.
we just list internal documents and stuff for the employees to look at so i got a php script for that to list all pdfs in a certain directory. i didnt want to use the download module as i needed to also keep this similar to the out flat file perl script used before.
as this progresses i can certainly staRt making use of the modules and write a few of my own for this, but for now, it was an ugent task that needed to get done here and i didntr have a lot of time to learn everything so i just used my php knowledge i lack and whip somehting up rather hastily, but thanks again for all your help..
Couple of suggestions
If you remove "action" in the form field completly, it will use the current page as the action.
I don't really know for sure, but I would change "if ( $_POST['frmMail'] )" to "if ( $_POST['txtMsg'] )", because I'm not sure if the form name is submitted. You could even do "if(strlen($_POST['txtMsg'])>5)", which would make sure the message is long enough.
--
Bradlis7.com | Churchofchristnet
--
Fish Hook Web Design
well
this seems to do the trick! thanks
i just need to do some error checking (like if option is blank and output messages as if it fails it wont be displayed in the form..
How are you capturing $_POST data?
I'm facing a similar situation - I understand the case for using Forms API but there are times I want to make my own self-submitting form using PHP in a page. It works except that the $_POST data is not captured on submission - I'm guessing that it's intercepted by the Forms module? E.g. the test code below will create a form that self-submits (thanks for the tip about leaving out the "action=" parameter in the form tag), but the posted variables "_submit_check" and "FirstName" come up empty after submission:
<?php
echo "_submit_check value is:" . $_POST['_submit_check'] . "<br />\n";
echo "FirstName value is:" . $_POST['FirstName'];
?>
<p>Please fill out the form below and then click the Send button.<br /></p>
<form name="testForm" method="post">
<table>
<tr>
<td width="110">First Name </td>
<td><input type="text" name="FirstName" maxlength="75" size="50"/></td>
</tr>
<tr>
<td colspan="2" align="left">
<input type="submit" name="Submit" value="Send"/></td>
</tr>
</table>
<input type="hidden" name="_submit_check" value="1"/>
</form>
I have got the same problem.
I have got the same problem. But the form works perfect with admin users and no registered ones.
Did you check that?
Not sure how to fix that.
Thanks