Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-07-18 17:53:12

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Creating a contact form that writes to the database and sends email

I’m using zem_contact_reborn for a feedback form on a site, and what I’d like to do is, in addition to having the user input emailed to whoever is listed on the form, I’d like to have the user input written to the database so that it can be pulled, sorted, etc. to my heart’s content.

Has this been done before? Could anyone point me to a post or a plugin or something that might get me headed in the right direction? If not, any ideas on what’s the best way to go about it? I like the security and spam-freeness of zem_contact, but I’m open to using a different approach, as long as I don’t end up with a database/inbox full of garbage.

Last edited by frickinmuck (2011-07-18 17:53:45)


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#2 2011-07-18 18:50:49

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Creating a contact form that writes to the database and sends email

You could have a look here

I am not sure which one, you can use this link as a reference so you can search here on the forum.

Good luck with the minor documentation :P


<txp:way_too_cool />

Offline

#3 2011-07-18 18:53:45

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Creating a contact form that writes to the database and sends email

One time I gave up setting up attachment with the contact form… I stumbled this

Link

I use this alongside with textpattern with extra database. This may help you if you cant find any solution


<txp:way_too_cool />

Offline

#4 2011-07-18 18:53:47

frickinmuck
Member
Registered: 2008-05-01
Posts: 118

Re: Creating a contact form that writes to the database and sends email

Thanks! I actually stumbled across this, which is looking promising. I’ll let you know how it works out.


The AI does not hate you, nor does it love you, but you are made out of atoms which it can use for something else.

Offline

#5 2011-07-18 18:56:28

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Creating a contact form that writes to the database and sends email

The link you send me is interesting, but have a look at the first comment. its all in the first link I sent you


<txp:way_too_cool />

Offline

#6 2011-07-18 20:15:52

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: Creating a contact form that writes to the database and sends email

Hey,

I’m having a little trouble with the radio buttons. Basically, when you output a radio button with zem_contact, it comes with its own “value” field. How can I change this value field to what I want?

Offline

#7 2011-07-18 20:54:51

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Creating a contact form that writes to the database and sends email

Link

Group and label parameters are required

<txp:zem_contact_radio label="something" group="Something group" />
<txp:zem_contact_radio label="something" />
<txp:zem_contact_radio label="something" />


<txp:zem_contact_radio label="Medium" group="I like my steak" />
<txp:zem_contact_radio label="Rare" />
<txp:zem_contact_radio label="Well done" />

<txp:way_too_cool />

Offline

#8 2011-07-18 21:23:40

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: Creating a contact form that writes to the database and sends email

Hey Dimitri,

Thanks for that info, however, the problem is the field ‘value’ associated with each radio button that is generated automatically by the plugin.

I’m trying to get the value associated with a radio button, which would either be a 0 or a 1, and use those values to perform different functions, however, there seems to be no field ‘value’ assigned to a radio button and the one generated by the form is a big string of random characters that changes each time.

Any way to work around this problem?

Offline

#9 2011-07-18 21:52:01

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Creating a contact form that writes to the database and sends email

Not sure what you trying to say. Could you show me your code and the source code.


<txp:way_too_cool />

Offline

#10 2011-07-18 21:58:13

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: Creating a contact form that writes to the database and sends email

<p>Are you checked??</p> <p><txp:zem_contact_radio group="Check" label="Yes" checked="1" /><br /> <txp:zem_contact_radio group="Check" label="No" /></p>

brings up :

<p>Are you checked?</p> <p><input value="q7b7508b0cf15ec0b96a56426f4ec8296" type="radio" id="q7b7508b0cf15ec0b96a56426f4ec8296" class="zemRadio" checked="checked" /> <label for="q7b7508b0cf15ec0b96a56426f4ec8296" class="zemRadio">Yes</label><br /> <input value="q685c620ff5e57ec429ad8ccfbd447b7a" type="radio" id="q685c620ff5e57ec429ad8ccfbd447b7a" class="zemRadio" /> <label for="q685c620ff5e57ec429ad8ccfbd447b7a" class="zemRadio">No</label></p>

The value changes randomly. Is there anyway to assign a custom value to radio buttons?

Offline

#11 2011-07-18 22:11:48

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Creating a contact form that writes to the database and sends email

I just remembered, zem does add random values. I dont think you need to worry about it, the plugin will automatically pick up the selected radio and will send the label value through the email.

I saw a small error in your tag, you added two groups… but it wont make a different
<p>Are you checked??</p> 
<p>
	<txp:zem_contact_radio group="Check" label="Yes" checked="1" />
	<txp:zem_contact_radio label="No" />
</p>

Last edited by Dimitri (2011-07-18 22:12:57)


<txp:way_too_cool />

Offline

#12 2011-07-19 14:42:38

lithium002
Member
Registered: 2011-04-29
Posts: 25

Re: Creating a contact form that writes to the database and sends email

Hey Dimitri,

I know it sends out the actual value in the email, however, I need the value before it is sent out for other purposes. :(

Offline

#13 2011-07-19 14:44:44

Dimitri
Member
From: Johannesburg
Registered: 2010-10-31
Posts: 129

Re: Creating a contact form that writes to the database and sends email

Ah k
Good luck, I advice you to post this thread to the plugin support


<txp:way_too_cool />

Offline

#14 2011-07-19 19:29:11

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Creating a contact form that writes to the database and sends email

Please read this thread before implementing Kevin’s (graphicPUSH) code. I myself and Ruud give some security related advices there which you should take into consideration.

For example do not trust and save the POST values blindly directly as Kevin advices. You do not want run into database filled with spam and other nasty stuff.

Instead it’s better to use zemcontact.submit callback and $zem_contact_values global array to handle the data, and use doSlash() to clean the values to avoid SQL injections. It’s also advisable to check posts status with get_zemcontact_evaluator() before saving anything to make sure the comment isn’t flagged as spam by an anti-spam plugin. Both anti-spam plugins and the saving function will be using the same callback after all.

As outlined in the forum thread I mentioned all you need to do to save comment data is something like this (untested, just an example, use with caution):

/**
	Registers the callback. xxx_my_saving_function() is
	now loaded on 'zemcontact.submit' event. You can find
	the callback spot from ZRC's source and what it can offer.
*/

register_callback('xxx_my_saving_function','zemcontact.submit');

/**
	The function that does the work on
	the submit event
*/

function xxx_my_saving_function() {
	/*
		get_zemcontact_evaluator() tells us if the comment is
		flagged as spam by an other plugin using the same callback.
		If spam, do not save the comment.

		PS. Remember to load the spam plugins
		before this plugin; set this plugin's load order to '6'
		and the anti-spam plugins '5'.

		We want to do the spam checks before this point.
	*/

	$evaluation =& get_zemcontact_evaluator();

	/*
		It's spam, end here
	*/

	if($evaluation->get_zemcontact_status() != 0)
		return;

	/*
		Saving the data goes here etc..
		$zem_contact_values global array holds
		all the form data.
	*/

	global $zem_contact_values;

	$set = 'timestamp=now()';

	foreach($zem_contact_values as $name => $val) {
		$set .= ', '. $name . "='" . doSlash($value) . "'";
	}

	/*
		Insert row to the database table
		named "xxx_enquiries_table".
	*/

	safe_insert(
		'xxx_enquiries_table',
		$set
	);
}

The code can be loaded as a plugin. Everything is prefixed to avoid conflicts with other core functions, plugins and tables.

Last edited by Gocom (2011-07-19 19:47:31)

Offline

Board footer

Powered by FluxBB