Custom Form

Third Party Plugins to CMSimple - how to install, use and create plugins

Moderator: Tata

Post Reply
delan10
Posts: 32
Joined: Sat May 24, 2008 6:18 pm

Custom Form

Post by delan10 » Wed Jun 18, 2008 4:35 pm

Hello

I use the custom mailform provided by cmsimple wiki (see original code below).
<TEXTAREA style="WIDTH: 101.34%; HEIGHT: 275px" rows=14>
#CMSimple // Custom mailform for CMSimple version 2.4
$reciever='somebody@somedomain.dk';
$message="\n\nThis is an automatic generated mail.\n\nSincerely\nThe Webmaster";
$recievermessage="\n\nThis is an automatic generated mail.";
// Define your field names and add extra lines for select options
// Use _ for spaces
$fields=array('name','adress','zip','Define_your_own','email');
$select['adress']=array('none','elephant','cow','tiger');
$tx['mailform']['recieptnotsend']="Could not send reciept.";
// DO NOT CHANGE CODE BELOW!
function mtr($tk){if (is_array($GLOBALS['select'][$tk]))$t=select($tk); else $t='<input type="text" class="text" name="'.$tk.'" value="'.$GLOBALS[$tk].'">';
return '<tr><td>* '.ucfirst(preg_replace('/\_/',' ',$tk)).'</td><td>'.$t.'</td></tr>';}
function select($tk){$t='';foreach($GLOBALS['select'][$tk] as $i){$t.='<option value="'.$i.'"';
if($GLOBALS[$tk]==$i)$t.=' selected';
$t.='>'.$i.'</option>';} return '<select class="text" name="'.$tk.'">'.$t.'</select>';}
$t='';$mailbody='';
if($action=='send'){foreach($fields as $i){initvar($i);if($GLOBALS[$i]=='')$e.='<li>You need to write '.$i;else $mailbody.=$i.': '.$GLOBALS[$i]."\n";}if(!(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[_a-z0-9-]+(\.[_a-z0-9-]+)*(\.([a-z]{2,4}))+$",$email)))$e.='<li>'.$tx['error']['mustwritemail'].'.';else if($e==''){initvar('txtarea');$mailbody.=$txtarea;if(!(@mail($reciever,'Mailform from '.sv('SERVER_NAME'),$mailbody.$recievermessage,"From: ".$email."\r\n"."X-Remote: ".sv('REMOTE_ADDR')."\r\n")))$e.=tag('li').$tx['mailform']['notsend'];else {$t=tag('p').$tx['mailform']['send'].tag('/p');if(!(@mail($email,'Copy of mailform from '.sv('SERVER_NAME'),$mailbody.$message,"From: ".$reciever."\r\n"."X-Remote: ".sv('REMOTE_ADDR')."\r\n")))$e.='<li>'.$tx['mailform']['recieptnotsend'];}}}if($t==''||$e!=''){
$t='<form action="'.$sn.'" method="post"><input type="hidden" name="selected" value="'.$u[$s].'"><input type="hidden" name="action" value="send"><table cellpadding="5" cellspacing="0" border="0">';
foreach($fields as $field)$t.=mtr($field);
$t.='<tr><td colspan="2">Message:<br><t'.'extarea rows="6" cols="40" name="t'.'xtarea"></t'.'extarea></td></tr>';
$t.='</table><p><input type="submit" class="submit" value="'.$tx['mailform']['sendbutton'].'"></p></form>'; }
$output=preg_replace('/<textarea.*textarea>/is',$t,$c[$s]);#
</TEXTAREA>
Some problems / requests :

1/ With IE the form keeps too small, whatever the “cols” value I specify.
This is curious because the with Firefox everything is OK : the form gets larger when the cols value is higher...

2/ How to add a captcha to this form ?

3/ By default all the fields are required. How to change this ?

Thanks in advance for your help.
And sorry for my poor english...
François - France
:)

ZiPs
Posts: 633
Joined: Thu May 22, 2008 6:17 pm
Location: Faxe, Denmark
Contact:

Re: Custom Form

Post by ZiPs » Wed Jun 18, 2008 5:39 pm

Hi dilan10

It is shown in CMSimple Wiki how to insert a mailform of your own choice, I am sure you also can add a captcha to it.

Personalized Reply Page
http://cmsimplewiki.com/doku.php/tips_a ... reply_page

/ZiPs
Preben Dahl | Webmaster cmsimple.dk | Projekt-og domæne ejer Gert Ebersbach

delan10
Posts: 32
Joined: Sat May 24, 2008 6:18 pm

Re: Custom Form

Post by delan10 » Wed Jun 18, 2008 5:52 pm

Thank you very much. :)
I'll have a look to your link, but I'm afraid I'm not competent enough for these kind of work...

I'd prefer to stick with the above code, which suits my needs well except for some details.
Can someone explain me why firefox understands the "cols" value while IE does not ?
This is the most annoying thing for me, because it makes the form much too small on the page and this is not very beautiful !

ZiPs
Posts: 633
Joined: Thu May 22, 2008 6:17 pm
Location: Faxe, Denmark
Contact:

Re: Custom Form

Post by ZiPs » Wed Jun 18, 2008 6:13 pm

Thats ok, but here is what I have done with cols

In code below in the mailform, there is a class text set the width in templates css,

Code: Select all

<input type="text" class="text" name="'.$tk.'" value="'.$GLOBALS[$tk].'">
if you dont have this class ind css make this and change 350 to you width

Code: Select all

.text {width:350px;}
/ZiPs
Preben Dahl | Webmaster cmsimple.dk | Projekt-og domæne ejer Gert Ebersbach

delan10
Posts: 32
Joined: Sat May 24, 2008 6:18 pm

Re: Custom Form

Post by delan10 » Wed Jun 18, 2008 6:25 pm

Thanks for your help but I don't understand what you mean !
Where shall I specify the width ?
Can you please give me the whole code with the modification ?

ZiPs
Posts: 633
Joined: Thu May 22, 2008 6:17 pm
Location: Faxe, Denmark
Contact:

Re: Custom Form

Post by ZiPs » Wed Jun 18, 2008 6:47 pm

Of course, here are all code with a width of 350px

As you can see, I have added style="width: 350px" in mailformen then you do not have to change your css

Code: Select all

<TEXTAREA style="WIDTH: 101.34%; HEIGHT: 275px" rows=14>
#CMSimple // Custom mailform for CMSimple version 2.4
$reciever='somebody@somedomain.dk';
$message="\n\nThis is an automatic generated mail.\n\nSincerely\nThe Webmaster";
$recievermessage="\n\nThis is an automatic generated mail.";
// Define your field names and add extra lines for select options
// Use _ for spaces
$fields=array('name','adress','zip','Define_your_own','email');
$select['adress']=array('none','elephant','cow','tiger');
$tx['mailform']['recieptnotsend']="Could not send reciept.";
// DO NOT CHANGE CODE BELOW!
function mtr($tk){if (is_array($GLOBALS['select'][$tk]))$t=select($tk); else $t='<input type="text"  style="width: 350px" name="'.$tk.'" value="'.$GLOBALS[$tk].'">';
return '<tr><td>* '.ucfirst(preg_replace('/\_/',' ',$tk)).'</td><td>'.$t.'</td></tr>';}
function select($tk){$t='';foreach($GLOBALS['select'][$tk] as $i){$t.='<option value="'.$i.'"';
if($GLOBALS[$tk]==$i)$t.=' selected';
$t.='>'.$i.'</option>';} return '<select class="text" name="'.$tk.'">'.$t.'</select>';}
$t='';$mailbody='';
if($action=='send'){foreach($fields as $i){initvar($i);if($GLOBALS[$i]=='')$e.='<li>You need to write '.$i;else $mailbody.=$i.': '.$GLOBALS[$i]."\n";}if(!(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[_a-z0-9-]+(\.[_a-z0-9-]+)*(\.([a-z]{2,4}))+$",$email)))$e.='<li>'.$tx['error']['mustwritemail'].'.';else if($e==''){initvar('txtarea');$mailbody.=$txtarea;if(!(@mail($reciever,'Mailform from '.sv('SERVER_NAME'),$mailbody.$recievermessage,"From: ".$email."\r\n"."X-Remote: ".sv('REMOTE_ADDR')."\r\n")))$e.=tag('li').$tx['mailform']['notsend'];else {$t=tag('p').$tx['mailform']['send'].tag('/p');if(!(@mail($email,'Copy of mailform from '.sv('SERVER_NAME'),$mailbody.$message,"From: ".$reciever."\r\n"."X-Remote: ".sv('REMOTE_ADDR')."\r\n")))$e.='<li>'.$tx['mailform']['recieptnotsend'];}}}if($t==''||$e!=''){
$t='<form action="'.$sn.'" method="post"><input type="hidden" name="selected" value="'.$u[$s].'"><input type="hidden" name="action" value="send"><table cellpadding="5" cellspacing="0" border="0">';
foreach($fields as $field)$t.=mtr($field);
$t.='<tr><td colspan="2">Message:<br><t'.'extarea rows="6" cols="40" name="t'.'xtarea"></t'.'extarea></td></tr>';
$t.='</table><p><input type="submit" class="submit" value="'.$tx['mailform']['sendbutton'].'"></p></form>'; }
$output=preg_replace('/<textarea.*textarea>/is',$t,$c[$s]);#
</TEXTAREA>
/ZiPs
Last edited by ZiPs on Wed Jun 18, 2008 7:05 pm, edited 1 time in total.
Preben Dahl | Webmaster cmsimple.dk | Projekt-og domæne ejer Gert Ebersbach

delan10
Posts: 32
Joined: Sat May 24, 2008 6:18 pm

Re: Custom Form

Post by delan10 » Wed Jun 18, 2008 7:04 pm

Great ! Thank you :)

Do you know if some of these attributes could work for the form : margin-left, padding-left, align ?

And do you know how to choose whether a particular field should be required or allowed to be left empty ?

ZiPs
Posts: 633
Joined: Thu May 22, 2008 6:17 pm
Location: Faxe, Denmark
Contact:

Re: Custom Form

Post by ZiPs » Wed Jun 18, 2008 7:14 pm

Yes they're also work in form, they must be in a style or class to your stylesheet

Unfortunately, I do not think you can change required field

/ZiPs
Preben Dahl | Webmaster cmsimple.dk | Projekt-og domæne ejer Gert Ebersbach

delan10
Posts: 32
Joined: Sat May 24, 2008 6:18 pm

Re: Custom Form

Post by delan10 » Wed Jun 18, 2008 8:00 pm

Thanks
:)

ZiPs
Posts: 633
Joined: Thu May 22, 2008 6:17 pm
Location: Faxe, Denmark
Contact:

Re: Custom Form

Post by ZiPs » Thu Jun 19, 2008 4:18 am

you are welcome :D

/ZiPs
Preben Dahl | Webmaster cmsimple.dk | Projekt-og domæne ejer Gert Ebersbach

Post Reply