I am trying to program a function that should do the following :

- check for an email adress in a database
- if not -> save the new adress
- if already exists -> ask to save anyway
- if no -> cancel and put the first email adres back in the form
- if yes -> save

I get it almost working right :) Here is the code i've written :

// modification email du compte principal
function ModifierEmail()
        var emailRegEx = new RegExp( "^\\w[\\w+\.\...@[\\w\-]+\.\\w[\\w+\.\-]*
\\w$", "gi" ) ;
        var email =$F('compteemail');
        var email2 =$F('emailorigine');

        if(email == "")
                alert("Merci de saisir une adresse email avant de valider.");
        else if(email.search(emailRegEx) == -1)
                alert("L'adresse email saisie n'est pas valide.");
        else if(email == email2)
                alert("Veuillez modifier l'adresse email avant de valider.");
                var url_ajax = 'fiche_joueur_email.fr.php';
                var target_ajax = 'messagemodifieremail';
                var params_ajax = Form.serialize("form_email");
                new Ajax.Updater(target_ajax,url_ajax, {parameters: 

// enregistrement email du compte principal
function EnregistrerEmail()
        new Ajax.Request(
                        parameters: Form.serialize("form_majemail"),
                        onSuccess: function() {
                                alert('email enregistré');
                        onFailure: function() { alert('Une erreur est survenue 
lors de la
procédure de mise à jour.'); }

Here is the first html form :

<form action="fiche_joueur.fr.php" method="post" name="form_email"
id="form_email" onsubmit="ModifierEmail(); return false;">
<input name="compteemail" id="compteemail" class="saisietextecourt"
value="ma...@toto.fr" type="text">
<button type="submit" class="boutonenvoyer" name="btn_envoyer"
<input name="emailorigine" id="emailorigine" value="ma...@toto.fr"
<input name="id_user" value="3174" type="hidden">
<input name="action" value="modifieremail" type="hidden">
<div id="messagemodifieremail"></div>

If the email already exists in the database, the Ajax.Updater presents
the following form in the messagemodifieremail div :

<div id="messageinformation">
L'adresse email saisie est déjà enregistrée dans la base de données.
Souhaitez-vous tout de même modifier cette adresse?
<form action="fiche_joueur.fr.php" method="post" name="form_majemail"
id="form_majemail" onsubmit="EnregistrerEmail(); return false;">
<div class="zoneboutons">
<button type="button" class="boutonsupprimer" name="btn_envoyer"
value="FALSE" onclick="Effect.BlindUp('messagemodifieremail'); $
<button type="submit" class="boutonenregistrer" name="btn_envoyer"
<input name="compteemail" id="compteemail" value="t...@gmail.com"
<input name="id_user" value="3174" type="hidden">
<input name="enregistrer" value="TRUE" type="hidden">
<input name="action" value="modifieremail" type="hidden">

It works allmost the right way. I change the email adres and if it
don't exist yet, it is changed in the database. If the email adres
allready exists, the second form shows up and ask if i want to save it
anyway. If i click on the save button, it gets saved and if i click on
the cancel button, the second form dissapears (Effect.BlindUp).

The main problem is that if i save the email adres in one of the two
ways and want to change it again, the ajax request doesn't seem to
work anymore (i saved it once and want to change it again). There are
no javascript error messages :/ I have checked my function (with some
alert()) and the second time i get till the Ajax.Updater function but
nothing happens then.
What could be the cause?

The next question concerns a way of presenting a message to the user
that says "saved" at the end of the first form (the one that calls the
ModifierEmail() function) if the email adres didn't exist in the db.
The Ajax.Updater could show a message in the messagemodifieremail div,
but it would have to get away after a few seconds. Any idea about
this? Maybe there is a way of checking if the div appears in the page
and if so launch some script that would use the Effect.BlindUp again?

If someone has some ideas about this, i am interested.

Thanks anyway.


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-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to