Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Send content of custom field as hidden information with zem_contact
I am working on a site (txp rev. 372) where I am using custom fields extensively for storing information. I’m using zem_contact for a contact form. Now I would like to send the content of one of the custom fields as (hidden) text when the form is sent. I can’t find a way to insert <txp:custom_field name=“my_fieldname” /> in the zem_contact attributes. Tried escaping the “ “ and / but that did not work.
-kees
Offline
Re: Send content of custom field as hidden information with zem_contact
bump…..
……or asked differently:
I really like the idea of sending custom_field information (like a hidden ID or product number) together with the contact information submitted by the user.
So I’m trying to find a way to insert the content of one of the custom fields (custom_1) together with the message content and, if possible, hidden for the user.
One way to do that (though not hidden) is by using the custom field as the subject of the email. The subject line is created in this line in the zem_contact plugin code:
$r = mail($mailto, "Email enquiry for $sitename", $msg, $headers);
It outputs the sitename after ‘Email equiry for’
If I could insert the contents of custom_1 instead of $sitename it would be great. Having not more than very basic php knowledge I’m a bit lost. How should I do that? Either by hacking/adding some lines in the plugin code (which I have to translate anyway) or with a clever way to insert <txp:custom_field name="my_field_name" />
somewhere.
If I try to do something like this:
<txp:zem_contact_text label="custom_field_name" default="<txp:custom_field name="custom_field_name" />" />
or:
<txp:zem_contact_hidden value="<txp:custom_field name="custom_field_name" />" />
It is not working because of the double />
, and I can’t find a way to ‘escape’ these.
I’m using rev. 433
-kees
Offline
Re: Send content of custom field as hidden information with zem_contact
I am not a programmer, but this works for me.
Fllow the steps .. Textpattern > admin > plugins > zem_contact> Edit
Enter the code available below at the bottom of the zem_contact code.
<blockquote>
<code>
function zem_contact_hidden($atts) {
global $zem_contact_error, $zem_contact_form;
$label = (empty($atts[‘label’]) ? ‘Text’ : $atts[‘label’]);
$name = (empty($atts[‘name’]) ? preg_replace(‘/\W/’, ‘’, $label) : $atts[‘name’]);
$break = (!isset($atts[‘break’]) ? ‘<br />’ : $atts[‘break’]);
$size = (empty($atts[‘size’]) ? ‘’ : $atts[‘size’]);
$min = (empty($atts[‘min’]) ? 0 : $atts[‘min’]);
$max = (!isset($atts[‘max’]) ? 100 : $atts[‘max’]);
$default = (empty($atts[‘default’]) ? ‘’ : $atts[‘default’]);
$required = (empty($atts[‘required’]) ? false : true);
$size = ($size ? ‘size=”’.(int)$size.’”’ : ‘’); $maxlength = ($max ? ‘maxlength=”’.(int)$max.’”’ : ‘’);
$default = ($default ? ‘’.$default.’”’ : ‘’); $v = (ps($name) ? ps($name) : $default);
if ($v and $max) $v = substr($v, 0, $max);
if (ps(‘zem_contact_submit’) and $required and empty($v)) $zem_contact_error[] = “Required field $label is missing”; elseif (ps($name) and $min and strlen($v) < $min) $zem_contact_error[] = “$label must be at least $min characters”; elseif (ps($name)) $zem_contact_form[$label] = $v;
$l = ($required ? “<b>$label</b>” : $label);
return ‘<input type=“hidden” name=”’.$name.’” id=”’.$name.’” value=”’.$default.’” ‘.$size.’ ‘.$maxlength.’ />’;
}
</code>
</blockquote>
<blockquote>
Use <code><txp:zem_contact_hidden label=“Hidden field” default=“This is the default value” /></code> along with the other elements in the form.
</blockquote>
ZEM: Hope you dont mind.
Last edited by creativesplash (2005-06-20 15:26:58)
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: Send content of custom field as hidden information with zem_contact
> creativesplash wrote:
<blockquote>
Use <code><txp:zem_contact_hidden label=“Hidden field” default=“This is the default value” /></code> along with the other elements in the form.
</blockquote>
Thanks creativesplash, this indeed works nicely for adding hidden fields! That solved half of my problem. But I still like to find a way to insert the content of a custom_field in this hidden field and send it with the form.
At least nested tags aren’t working:
<blockquote>
<txp:zem_contact_hidden label="custom_field_name" default="<txp:custom_field name="custom_field_name">" />
</blockquote>
any idea?
-k
Last edited by kees-b (2005-06-20 17:38:48)
Offline
Re: Send content of custom field as hidden information with zem_contact
<code>
<txp:zem_contact mailto=“creativesplash@gmail.com”>
<txp:zem_contact_text label=“Name” /><br />
<txp:zem_contact_email /><br />
<txp:zem_contact_hidden label=“What ever label you want” default=“What ever content you want” />
<txp:zem_contact_textarea label=“Message” /><br />
<txp:zem_contact_submit label=“Send” />
</txp:zem_contact>
</code>
Works for me.
I’m pasting the contents of the email I got when I used the above tag.
<blockquote>
Name: Vasanth
Email: creativesplash@yahoo.com
What ever label you want: What ever content you want
Message: This is a test message.
</blockquote>
hope this helps.
p.s. If you dont mind may I know the purpose of using hidden fields? What kind of content are you going to hide?
Last edited by creativesplash (2005-06-20 17:54:01)
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: Send content of custom field as hidden information with zem_contact
Hello Vasanth,
Your example works perfectly for me too! But for the site I am working on currently I am using the textpattern custom fields extensively. Most of the custom fields content is displayed on the site, output by the <txp:custom_field name="custom_field_name" />
tag. One custom field is reserved to store extra information (an identification number) that does not have to be hidden but is of no meaning for the visitors of the site. It only has to be sent along with the message to have a quick connection with data that are offsite when the message is received.
-kees
Offline
Re: Send content of custom field as hidden information with zem_contact
Custom fields can be used only inside article forms. So create a form with custom fields and use the <code><txp:article_custom form=“custom_form” section=“some section” sortby=“Posted” sortdir=“desc” /></code> to get the content of the custom field.
Your zem_contact form should look like this…
<code>
<txp:zem_contact mailto=“creativesplash@gmail.com”>
<txp:zem_contact_text label=“Name” /><br />
<txp:zem_contact_email /><br />
<txp:zem_contact_hidden label=“What ever label you want” default=”<txp:article_custom form=“custom_form” section=“some section” sortby=“Posted” sortdir=“desc” />” />
<txp:zem_contact_textarea label=“Message” /><br />
<txp:zem_contact_submit label=“Send” />
</txp:zem_contact>
</code>
I am not sure if it will work. Just give it a try.
Last edited by creativesplash (2005-06-21 04:02:25)
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: Send content of custom field as hidden information with zem_contact
You are right about the article form. I tried that allready. But the problem lies in the nesting of tags.
If a tag is used as an attribute in another tag it is not working. I think the only solution is to use either the php code that outputs the custom_field of choice or modify the plugin code and add some code that outputs custom field content as the default content of a hidden field.
Something like a function:
<txp:zem_contact_hidden_custom label="What ever label you want" default="custom_field_name">
Where default=“custom_field_name” outputs the content of the specified field.
Any coders willing to help?
Offline
#9 2005-06-21 09:38:15
- heikki74
- Member
- From: Finland
- Registered: 2004-08-17
- Posts: 100
Re: Send content of custom field as hidden information with zem_contact
Modify the code that creativesplash provided like this:
line 1:
function zem_contact_hidden($atts) {
to:
function zem_contact_hidden($atts, $thing) {
line 14:
$default = ($default ? ‘’.$default.’”’ : ‘’);
to:
$default = trim(parse($thing));
And use the tag like this:
<code><txp:zem_contact_hidden label=“What ever label you want”>
<txp:some_inner_tag_of_your_choise />
</txp:zem_contact_hidden></code>
<br />
That should output:
<code><input type=“hidden” name=“Whateverlabelyouwant” id=“Whateverlabelyouwant” value=“something from inner tag” maxlength=“100” /></code>
Last edited by heikki74 (2005-06-21 09:49:17)
Offline
Re: Send content of custom field as hidden information with zem_contact
bingo!
heikki74 you made my day
and I even understand what’s happening under the hood – I definitively will make a dive into php (apart from the sea) this summer
thanks again both!
Offline
Re: Send content of custom field as hidden information with zem_contact
Sorry I couldnt help you fully. But I did try :)
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: Send content of custom field as hidden information with zem_contact
> creativesplash wrote:
> Sorry I couldnt help you fully. But I did try :)
Yes, and you speeded up this ‘sleeping’ thread with a very helpfull answer!
thanks!
Offline