Welcome Guest, Not a member yet? Register   Sign In
facebox form submission
#1

[eluser]zorka[/eluser]
Hello,

I have a standard login page with a standard FORGOT PASSWORD option. I am poping up a FACEBOX when people click on FORGOT PASSWORD. QUESTION: I want to do standard validation in the facebox as I would in a "regular" browser window. The facebox loads, but as soon as I hit submit, the form loads again in a non-facebox window (the correct error shows, but it's in a regular browser window, not a facebox!). How do I keep facebox "lit" after submit?

Code:
<head>
   [removed]
    jQuery(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        loading_image : 'loading.gif',
        close_image   : 'closelabel.gif'
      })
    })
     $.facebox.settings.opacity = 0.35;
   [removed]
</head>

...

<a href="/login/password" rel="facebox">I forgot my password</a>

----
the function /login/password (function:password in controller:login) loads the FORGOT PASSWORD VIEW:

Code:
function password() {    
        $rules['email']    = "trim|required|valid_email|callback__password_check";
        $this->validation->set_rules($rules);
            
        if ($this->validation->run() == FALSE)
        {
            $data['title'] = 'Deals On Meals: Login';
            $this->load->view('login/password_form');
        }
        else
        {
                   $this->sendpassword();
        }
    }



FORGOT PASSWORD VIEW:
Code:
&lt;?php echo form_open('login/password'); ?&gt;
        <table id="popupLayout" style="border-collapse:separate;" cellspacing="5" align="center">
            <tr>
               <td class="formheader" colspan="2">Please enter your email address</td>
           </tr>
            
            <tr><td colspan="2">&lt;?php echo $this->validation->error_string; ?&gt;</td>
            </tr>
            <tr>
               <td height="33">Email</td>
               <td>&lt;input type="text" name="email" id="email"&gt;&lt;/td>
            </tr>    
                    <tr>
                       <td>&nbsp;</td>
                       <td>&lt;input class="login" type="submit" name="submit" value="Submit" /&gt;
                           &lt;input class="close"&gt;&lt;/td>
                    </tr>
                    <tr>
                        <td colspan="2" id="surveycodemessage"></td>
                    </tr>
        </table>
   &lt;?php form_close(); ?&gt;
#2

[eluser]Xeoncross[/eluser]
I would use boxy as it looks better anyway.
(just did the same type of thing)

Either way, download that plugin for jQuery that re-scans the DOM after new items are loaded - I don't remember what it is called...
#3

[eluser]nevercraft[/eluser]
I've used facebox quite a bit with CI. Typically I write a simple plugin that handles the form validation from within the facebox.

You can change your form to include onsubmit="return validate_form()"

Then create a javascript function that checks your form fields and returns true or false. If it returns false, the form won't be submitted and you can use jQuery to display the errors. The facebox would stay open until the form submission was valid and returned true.

Some simple code you could use:
Code:
function validate_form() {
    var errors = '';
    var email_test = new RegExp("^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$", "ig");

    if ( ! email_test.test($('input[name=email]').val()))
    {
        errors += "<p>The Email address you've provided is not valid.  Please provide a valid email address.</p>";
    }

    if (errors != '')
    {
        errors = "<p>Error!</p>" + errors + "<p>Please try again</p>";
        // Add a div where you want the errors to show up in your form
        $('#somewarningcontainer').html(errors);
        return false;
    }
    else
    {
        return true;
    }
}

If you need to actually have validation happen server side, I'd create a function that used $.post to post to the URL. That would return the HTML to go inside of the facebox. Then you just clear the contents of the facebox body and append the returned HTML:
Code:
function submit_form() { // change your &lt;form&gt; to onsubmit="return submit_form()"
    $.post('/controller/method', { form post items }, function(data) {
        $('#facebox .content').empty();
        $('#facebox .content').html(data);
    });
    return true;
}

Hope it helps.
#4

[eluser]Xeoncross[/eluser]
Javascript from within HTML pages? hm.... I forgot you could do it that way!
I've spent way to long working with XHTML valid pages!
#5

[eluser]zorka[/eluser]
ThanX nevercraft, I will try that...

I was under the impression I would have to use AJAX to prevent the page reload but I'll try it...
btw: (I should have clarified earlier) The main validation I am doing is server side and relatively sensitive (retrieving user password) so I'd like to keep it secure.
#6

[eluser]Iverson[/eluser]
Use xajax buddy. That way all you'd have to do is throw an invisible div with your form on the main view. Use xajax and do the backend work server side then just update the form with the results asynchronously.
#7

[eluser]jdfwarrior[/eluser]
what directory structure did you use for the placement of your facebox files?

I made a "code" folder off the root of the domain, and then within it i have a css folder and a js folder. The facebox folder was placed in the js folder. From the main view though, the path is right to load the js and css files in the facebox folder, but I havent been able to get the facebox to load? It displays for a split second and then disappears and shows the contents of the desired php file in the main browser window.

Any ideas on what I could be doing wrong?




Theme © iAndrew 2016 - Forum software by © MyBB