[tw] Re: Help with Javascript email form

2010-10-07 Thread Tobias Beer
The easiest way to catch errors in such onclick handlers is ...to
catch them.

Wrap your onclick handler with...

try{

...
myCode();
...

}catch(e){
  alert(e); //show's you what's wrong
  return false; //prevents sumbission
}return true;

...then you would probably be notified of the fact that your form has
no inputs that go by the name of from, when, name or extratags ...so,
you need to create them, i.e.



Without those... your onclick handler will simply abort, yet the form
will keep on submitting... as you did not have any error handling to
prevent it from doing so.

Also, in terms of performance, I would guess it is better to create
your tagstring first and only in the end assign it to your form
element, i.e.:

var tgs='';
story.forEachTiddler(function(title, tiddler){
  tgs+='[['+title+']] ';
});
f.extratags.value=tgs;

Last but not least, there is hardly any use in putting linebreaks
behind hidden form elements.

Let me know if you're still at loss or if that helped.

Cheers, Tobias.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-07 Thread Tobias Beer
The easiest way to catch errors in such onclick handlers is ...to
catch them.

Wrap your onclick handler with...

try{

...
myCode();
...

}catch(e){
  alert(e); //shows you what's wrong
  return false; //prevents sumbission
}return true;

...then you would probably be notified of the fact that your form has
no inputs that go by the name of from, when, name or extratags ...so,
you need to create them, i.e.



Without those... your onclick handler will simply abort, yet the form
will keep on submitting... as you did not have any error handling to
prevent it from doing so.

Also, in terms of performance, I would guess it is better to create
your tagstring first and only in the end assign it to your form
element, i.e.:

var tgs='';
story.forEachTiddler(function(title, tiddler){
  tgs+='[['+title+']] ';
});
f.extratags.value=tgs;

Last but not least, there is hardly any use in putting linebreaks
behind hidden form elements.

Let me know if you're still at loss or if that helped.

Cheers, Tobias.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-07 Thread Tobias Beer
The easiest way to catch errors in such onclick handlers is ...to
catch them.

Wrap your onclick handler with...

try{

...
myCode();
...

}catch(e){
  alert(e); //shows you what's wrong
  return false; //prevents submission
}return true;

...then you would probably be notified of the fact that your form has
no inputs that go by the name of from, when, name or extratags ...so,
you need to create them, i.e.



Without those... your onclick handler will simply abort, yet the form
will keep on submitting... as you did not have any error handling to
prevent it from doing so.

Also, in terms of performance, I would guess it is better to create
your tagstring first and only in the end assign it to your form
element, i.e.:

var tgs='';
story.forEachTiddler(function(title, tiddler){
  tgs+='[['+title+']] ';
});
f.extratags.value=tgs;

Last but not least, there is hardly any use in putting linebreaks
behind hidden form elements.

Let me know if you're still at loss or if that helped.

Cheers, Tobias.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-07 Thread Tobias Beer
Actually, valid markup would be...



Cheers, Tobias.

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-07 Thread colmjude
Hi Skye,

I have had a quick look at your code and made a few tweaks. You don't
need the .value on the variables you add to f in your js.
Also the new date should read
= new Date();

Here is the amended code:

http://servername/
mailtext2.php" style="display:inline">
  
   
   Seu Comentario:
   
   
   Enter your information, then press
   
   

   server response:
   
   


It definitely creates a new tiddler with all the details. Hopefully it
will work on your server side too...? Let us know how you get on

colm

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-07 Thread Eric Shulman
> http://servername/
> mailtext2.php" style="display:inline">
...
>                          onclick="var f=this.form;
...
...
> I have two problems
> 1/ it does not create the tiddler in the TW...
> 2/ the mailtext2.php script sends the email, but the values of "when",
> "from" and "tags" and "name" are blank ...I think its the same
> issuethe code that defines these variables is not correctbut I
> cant see why?

When the SUBMIT input button ("send") is pressed, it triggers the FORM
elements action="...", but does not trigger the onclick handler
associated with the button.  To work around this, use an
onsubmit="..." handler in the  element, rather than an
onclick="..." handler in the  button.  Thus:

http://servername/mailtext2.php";
   onsubmit="var f=this;
  var target=f.nextSibling;
  target.style.display='block';
  f.when.value=newDate();
  f.from.value=config.options.txtUserEmail;
  f.name.value=config.options.txtUserName;
  f.extratags.value ='';
  story.forEachTiddler(function(title, tiddler){
 f.extratags.value +='[['+title+']] ';
  });
  config.options.txtTags=f.extratags.value;
  f.tags.value=f.extratags.value+' '+ f.name.value+' comment
temporary';
  store.saveTiddler(f.subj.value,f.subj.value,
f.msg.value,f.name.value,f.when.value,f.tags.value);
">
...
   
...

That should do it.  (Note: untested)

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-08 Thread skye riquelme
Hi All Again

still struggling a bit with this code.

the suggestion from colmjude does indeed create the new tiddler...but
it only passes the values of subj,msg and toto the php fileor
at least the php file only prints them outthe other values
calculated by the onclick handler dont show up in the email created by
the php file.

...so I tried Erics suggestionand got the code to be ...

http://server/mailtext2.php";  onsubmit=
"var f=this.form;
var target=this.form.nextSibling;
target.style.display='block';
f.when=new Date();
f.from=config.options.txtUserName+'( '+config.options.txtUserEmail
+' )';
f.name=config.options.txtUserName;
f.extratags ='';
story.forEachTiddler(function(title, tiddler){f.extratags += '[['+title
+']] ';});
f.tags=f.extratags+' '+ f.name+' comment temporary';
store.saveTiddler(f.subj.value,f.subj.value,f.msg.value,f.name,f.when,f.tags);
">


Seu Comentario:
   
   
   Enter your information, then press
   
   

   server response:
   Domain must be: ".
$sys.""; }


...how can I get it to use the onclick values and not the form
values ?

Thanks again
Skye

PS tobias...I am not sure exactly where to put the onclick wrapper you
mentioned.@!



On 8 Out, 00:22, Eric Shulman  wrote:
> > http://servername/
> > mailtext2.php" style="display:inline">
> ...
> >          >                 onclick="var f=this.form;
>
> ...
> ...
>
> > I have two problems
> > 1/ it does not create the tiddler in the TW...
> > 2/ the mailtext2.php script sends the email, but the values of "when",
> > "from" and "tags" and "name" are blank ...I think its the same
> > issuethe code that defines these variables is not correctbut I
> > cant see why?
>
> When the SUBMIT input button ("send") is pressed, it triggers the FORM
> elements action="...", but does not trigger the onclick handler
> associated with the button.  To work around this, use an
> onsubmit="..." handler in the  element, rather than an
> onclick="..." handler in the  button.  Thus:
>
>     action="http://servername/mailtext2.php";
>    onsubmit="var f=this;
>       var target=f.nextSibling;
>       target.style.display='block';
>       f.when.value=newDate();
>       f.from.value=config.options.txtUserEmail;
>       f.name.value=config.options.txtUserName;
>       f.extratags.value ='';
>       story.forEachTiddler(function(title, tiddler){
>          f.extratags.value +='[['+title+']] ';
>       });
>       config.options.txtTags=f.extratags.value;
>       f.tags.value=f.extratags.value+' '+ f.name.value+' comment
> temporary';
>       store.saveTiddler(f.subj.value,f.subj.value,
>             f.msg.value,f.name.value,f.when.value,f.tags.value);
> ">
> ...
>    
> ...
>
> That should do it.  (Note: untested)
>
> enjoy,
> -e
> Eric Shulman
> TiddlyTools / ELS Design Studios

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-09 Thread Tobias Beer
Hi Skye...

As for the try catch [1], you would simply wrap your whole handler
with it. So, again, at the beginning of your onclick (or rather
onsubmit handler as Eric thoughtfully suggests) you would put...

try{

Then the javascript that does things with tiddler contents and puts
them into form elements followed by...

}catch(e){
//do something with the error, e.g.
alert(e);
//abort submission
return false;
}

As explained before, not doing that will otherwise make the form
submit, which is not helpful, especially when trying to debug this.
However, you should see the javascript errors in your firebug console.
On the other hand if that would not generate a javascript error, then
you would know that the error now likely is on the php end... which
should show in the response unless you have turned off error reporting
in your php configuration.

As for your php bits, you did not post the crucial parts. On the other
hand, from what I am seeing in what you've posted, you could
drasticaly simplify it by doing the following:

//get post params
foreach($_REQUEST as $key => $value){$$key=$value;}

This will automagically turn the values of all form elements into php
variables by the same name, thus performing something like this (in
the background)...

$name = ValueOfiIputCalledNameAsString;

I would not mind debugging your form. Just send me an email [2] with
both the tiddler and the php file. However, only working on one end
makes the process somewhat difficult.

Cheers, Tobias.

[1] http://w3schools.com/JS/js_try_catch.asp
[2] click on my profile here

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.



[tw] Re: Help with Javascript email form

2010-10-09 Thread Tobias Beer
Hi Skye...

As for the try catch [1], you would simply wrap your whole handler
with it. So, again, at the beginning of your onclick (or rather
onsubmit handler as Eric thoughtfully suggests) you would put...

try{

Then the javascript that does things with tiddler contents and puts
them into form elements followed by...

}catch(e){
//do something with the error, e.g.
alert(e);
//abort submission
return false;
}

As explained before, not doing that will otherwise make the form
submit, which is not helpful, especially when trying to debug this.
However, you should see the javascript errors in your firebug console.
On the other hand if that would not generate a javascript error, then
you would know that the error now likely is on the php end... which
should show in the response unless you have turned off error reporting
in your php configuration.

As for your php bits, you did not post the crucial parts. On the other
hand, from what I am seeing in what you've posted, you could
drasticaly simplify it by doing the following:

//get post params
foreach($_REQUEST as $key => $value){$$key=$value;}

This will automagically turn the values of all form elements into php
variables by the same name, thus performing something like this (in
the background)...

$name = ValueOfInputCalled_name_AsString;

I would not mind debugging your form. Just send me an email [2] with
both the tiddler and the php file. However, only working on one end
makes the process somewhat difficult.

Cheers, Tobias.

[1] http://w3schools.com/JS/js_try_catch.asp
[2] click on my profile here and you should find it

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlyw...@googlegroups.com.
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.