OK, before you do anything with javascript, get the page working without it
first.  That code you wrote there will output a div inside the head when
it's submitted.Seriously, do that otherwise you will be troubleshooting 2
things at once.  Get it working without javascript first, always.

Also what is the source or documentation on validation.js?


On Tue, Sep 22, 2009 at 4:45 AM, MEM <tal...@gmail.com> wrote:

>  DJ Mangus, I’m really newbie here. :( I will server side validate. But
> right now, I just like to make this working.
>
>
>
> I'm trying to do the following:
>
> When the form data is send to an e-mail, the form disappears, and a div
> with new contents will appear.
>
>
>
> However, I'm unable to do so:
>
>
>
>
>
> Here is the full relevant code:
>
>
>
> <head>
>
>
>
> <script src="js/validation/scriptaculous/lib/prototype.js" type="text/
> javascript"></script>
>
> <script src="js/validation/validation.js" type="text/javascript"></script>
>
>
>
> <?php
>
>
>
>                if(isset($_POST['submit']))
>
>                {
>
>                               //recipients
>
>                               $to  = 'sendt...@gmail.com';
>
>
>
>                               $from = $_POST['contact_email'];
>
>
>
>                               // subject
>
>                               $subject = 'Some subject';
>
>
>
>                               // message
>
>                               $message = '
>
>                               <html>
>
>                                             <head>
>
>                                               <title>test</title>
>
>                                             </head>
>
>
>
>                                             <body>
>
>                                               <p>the subject was:' .
> $subject. '</p>
>
>                                             </body>
>
>                               </html>
>
>                               ';
>
>
>
>                               // To send HTML mail, the Content-type
> header must be set
>
>                               $headers  = 'MIME-Version: 1.0' . "\r\n";
>
>                               $headers .= 'Content-type: text/html;
> charset=UTF-8' . "\r\n";
>
>
>
>                               // Additional headers
>
>                               $headers .= 'From: Testingfrom <'.$from.'>'
> . "\r\n";
>
>
>
>                               // Mail it
>
>                               mail($to, $subject, $message, $headers);
>
>
>
>                               echo "<div>Thanks for your contact.</div>";
>
>
>
>                }
>
>
>
> ?>
>
>
>
> </head>
>
>
>
> <body>
>
> <div id="main">
>
>
>
> <p>Please fill in :</p>
>
> <div id="formWrapper">
>
> <form id="sendData" action="<?php echo $_SERVER['PHP_SELF']; ?>"
> method="post">
>
>
>
>                <fieldset>
>
>
>
>                               <legend>Form</legend>
>
>
>
>                               <div class="form-row">
>
>
>
>                                             <div class="field-label">
>
>                                                            <label for="
> contact_email">E-mail</label>:
>
>                                             </div>
>
>
>
>                                             <div class="field-widget">
>
>                                                            <input name="
> contact_email" id="contact_email" class="required validate-email"
> title="Insert e-mail." />
>
>                                             </div>
>
>
>
>                               </div>
>
>
>
>                               <div class="form-row">
>
>
>
>                                             <div class="field-label">
>
>                                                            <label for="url
> ">URL</label>:
>
>                                             </div>
>
>
>
>                                             <div class="field-widget">
>
>                                                            <input name="
> url" id="url" class="validate-url" title=" write it properly. URL" />
>
>                                             </div>
>
>
>
>                               </div>
>
>
>
>                </fieldset>
>
>
>
>                <input type="submit" value="Submit" name="submit" />
>
>
>
> </form>
>
>
>
>  </div>
>
>                <script type="text/javascript">
>
>
>
>                               function formCallback(result, sendData)
>
>                               {
>
>                        if(result == true)
>
>
>
>                                             $('formWrapper').innerHTML=
> 'Your form was successfully submitted!';
>
>                               }
>
>
>
>                               new Validation(sendData,{immediate:true,
> useTitles:true, onFormValidate:formCallback});
>
>
>
>                </script>
>
>
>
>
>
> </div>
>
>
>
> </body>
>
>
>
> </html>
>
>
>
>
>
> Thanks in advance,
>
> MEM
>
>
>
> *From:* prototype-scriptaculous@googlegroups.com [mailto:
> prototype-scriptacul...@googlegroups.com] *On Behalf Of *DJ Mangus
> *Sent:* domingo, 20 de Setembro de 2009 22:38
> *To:* prototype-scriptaculous@googlegroups.com
> *Subject:* [Proto-Scripty] Re: newbie - form submit
>
>
>
> Never rely on client side validation, that's for convenience for your
> users, not security.
>
> First, make the functionality works (including security) without
> javascript.
>
> Then override the submit button with javascript by observing the submit.
>  In that event code you submit the form via ajax, hide the div, display what
> you want, etc. then use event.stop to keep the default submit behavior
> from occurring.
>
>
>
> Good luck with this.
>
>
>
> Some links:
>
> http://api.prototypejs.org/dom/event.html#stop-class_method
>
> http://api.prototypejs.org/dom/document.html#observe-class_method
>
> and
>
> http://api.prototypejs.org/ajax/ajax/updater.html
>
> On Sun, Sep 20, 2009 at 9:47 AM, MEM <tal...@gmail.com> wrote:
>
>
> Hello all,
>
> I'd love to create a contact form using prototype and php.
> However, I want to make sure that, if the javascript is disable,
> the submission should be server side validated and submitted as well.
>
> If javascript is enable, the onclick event will trigger, hence, the js
> validation
> Will occur.
> If the javascript isn't enable, the onclick event will not trigger,
> so the submit button will get called, and the server side validation will
> occur.
>
> I don't know if it's precise, however, it works.
>
>
> Now what I'd like to do is, without leaving the same page,
> when the form is submitted, the div that contains the form gets hidden, and
> it should
> be replaced by a div telling: "The contact was send".
>
> I'm so newbie, that I've found a validation class called:
> "Really easy field validation with Prototype" and it seems to be very nice.
>
> Can anyone summarize the steps to accomplish this without losing the server
> side submission if, js
> Is disable somehow?
>
> Should I try to edit (I really don't like this idea) the validation class
> for doing this?
> Or can this be done otherwise?
>
>
> Thanks a lot to any feedback on this,
> Regards,
> MEM
>
>
>
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to