Laravel 4 Dynamic Multiple Object Form Post

时间:2014-04-28 08:06:05

标签: javascript php laravel laravel-4

我有User创建的表单和控件。

表格

{{ Form::open(array('url' => 'user', 'id' => 'user_create_form', 'class' => 'pure-skin-mine pure-form pure-form-aligned')) }}
            <div class="title_box">User Registration<i class="fa fa-edit"></i></div>
            <fieldset>
                <div class="pure-control-group">
                    <label for="name">Name</label>
                    {{ Form::text('name', Input::old('name'), array('placeholder' => 'Nama Lengkap')) }}
                </div>

                <div class="pure-control-group">
                    <label for="email">Email</label>
                    {{ Form::email('email', Input::old('email'), array('placeholder' => 'Email Address')) }}
                </div>

                <div class="pure-control-group">
                    <label for="password">Password</label>
                    {{ Form::password('password', array('placeholder' => 'Password')) }}
                </div>

                <div class="pure-control-group">
                    <label for="password_confirmation">Password Confirmation</label>
                    {{ Form::password('password_confirmation', array('placeholder' => 'Repeat the Password')) }}
                </div>

            <div class="pure-controls">
                <div id="captcha_container">{{Form::captcha()}}</div>           
                <label for="cb" class="pure-checkbox">
                    {{ Form::checkbox('agree', Input::old('agree')) }} Agree with the Term and Conditions
                </label>
                {{ Form::submit('Submit', array('class' => 'pure-button pure-button-primary')) }}
            </div>
            </fieldset>

{{ Form::close() }} 

控制器

class UserController extends BaseController {
    public function index()
    {
    }

    public function create()
    {
        return View::make('users.create');
    }

    public function store()
    {
        $rules = array(
            'name'                     => 'required',
            'email'                    => 'required|email|unique:users',
            'password'                 => 'required|confirmed|min:5',
            'recaptcha_response_field' => 'required|recaptcha',
            'agree'                    => 'required',
        );
        $validator = Validator::make(Input::all(), $rules);

        if ($validator->fails()) {
            return Redirect::to('/user/create')
                ->withErrors($validator)
                ->withInput(Input::except('password'));
        } else {
            // store

            $random_hash = substr(md5(uniqid(rand(), true)), 16, 16);
            $link = Input::get('email').$random_hash;
            $link_encoded = urlencode($link);

            $user = new User;
            $user->name       = Input::get('name');
            $user->email      = Input::get('email');
            $user->password   = md5(Input::get('password'));
            $user->confirmation = $link;
            $user->confirmed = false;
            $user->photo = 'default.jpg';
            $user->thumbnail = 'default_thumb.jpg';
            $user->save();

            $contactName = $user->name;
            $contactEmail = $user->email;

            $data = array('name'=>$contactName, 'email'=>$contactEmail, 'link'=>$link_encoded);
            Mail::send('emails.confirmation', $data, function($message) use ($contactEmail, $contactName)
            {
                $message->to($contactEmail, $contactName)->subject('Confirm your account');
            });

            // redirect
            return Redirect::to('/user/success');
        }
    }

    public function show($id)
    {
        //
    }

    public function edit($id)
    {
        //
    }

    public function update($id)
    {
        //
    }

    public function destroy($id)
    {
        //
    }
}

代码用于创建表单之外的单个用户。它运作良好。现在我希望能够创建多个用户,并且使用javascript在视图中动态确定用户数量。我该怎么做?

0 个答案:

没有答案