Is there a way to change the html output from wp_login_form(), so that is like the bootstrap form?
The wp_login_form looks like this:
<form class="form-grey" name="loginform" id="loginform" action="http://domain.loc/wp-login.php" method="post">
<p class="login-username">
<label for="user_login">Username</label>
<input type="text" name="log" id="user_login" class="input" value="" size="20">
</p>
<p class="login-password">
<label for="user_pass">Password</label>
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20">
</p>
<p class="login-remember"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever"> Remember Me</label></p>
<p class="login-submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="Log In">
<input type="hidden" name="redirect_to" value="http://domain.loc/">
</p>
</form>
And Bootstrap Forms look like this:
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail3">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail3" placeholder="Email">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputPassword3">Password</label>
<input type="password" class="form-control" id="exampleInputPassword3" placeholder="Password">
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-default">Sign in</button>
</form>
Try to use this :
Take your arguments as per the classes and IDs required :
$args = array(
'echo' => true,
'redirect' => property_list(),
'form_id' => 'loginform',
'label_username' => '',
'label_password' => '',
'label_remember' => __('Keep me logged in'),
'label_log_in' => __('SIGN IN'),
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
'remember' => true,
'value_username' => NULL,
'value_remember' => false
);
Now pass this $args array to function below :
<?php wp_login_form_custom($args);?>
Now you can use this function as defined below :
function wp_login_form_custom($args = array()) {
//you can use the values as $args['form_id'] and so on
//create you own HTML here with classes and IDs defined in the $args
}
Related
Here's the code for my HTML I just want to see the image, not the file name. The form is on the registration side of WordPress I passed all the data except on the attachment file, I checked some tutorials but I can't do it. Thank you.
<form method="POST" action="<?php echo esc_url( admin_url('admin-post.php') ); ?>">
<?php if (isset($_COOKIE['register_error'])) { ?>
<div class="alert alert-danger" role="alert">
<?php echo $_COOKIE['register_error']; ?>
</div>
<?php } ?>
<input type="hidden" name="action" value="register_account">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>First Name <span title="required">*</span></label>
<input type="text" class="form-control" name="firstname" value="<?php echo isset($_COOKIE['register_firstname']) ? $_COOKIE['register_firstname'] : ''; ?>" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Last Name <span title="required">*</span></label>
<input type="text" class="form-control" name="lastname" value="<?php echo isset($_COOKIE['register_lastname']) ? $_COOKIE['register_lastname'] : ''; ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Phone <span title="required">*</span></label>
<input type="text" class="form-control" name="phone" value="<?php echo isset($_COOKIE['register_phone']) ? $_COOKIE['register_phone'] : ''; ?>" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Company <span title="required">*</span></label>
<input type="text" class="form-control" name="company" value="<?php echo isset($_COOKIE['register_company']) ? $_COOKIE['register_company'] : ''; ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label>Address <span title="required">*</span></label>
<input type="text" class="form-control" name="address" value="<?php echo isset($_COOKIE['register_address']) ? $_COOKIE['register_address'] : ''; ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>City <span title="required">*</span></label>
<input type="text" class="form-control" name="city" value="<?php echo isset($_COOKIE['register_city']) ? $_COOKIE['register_city'] : ''; ?>" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>State <span title="required">*</span></label>
<input type="text" class="form-control" name="state" value="<?php echo isset($_COOKIE['register_state']) ? $_COOKIE['register_state'] : ''; ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="form-group">
<label>Zip Code <span title="required">*</span></label>
<input type="text" class="form-control" name="zipcode" value="<?php echo isset($_COOKIE['register_zipcode']) ? $_COOKIE['register_zipcode'] : ''; ?>" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Email Address <span title="required">*</span></label>
<input type="email" class="form-control" name="email" value="<?php echo isset($_COOKIE['register_email']) ? $_COOKIE['register_email'] : ''; ?>" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Username <span title="required">*</span></label>
<input type="text" class="form-control" name="username" value="<?php echo isset($_COOKIE['login_username']) ? $_COOKIE['login_username'] : ''; ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12" id="password-field"></div>
<div class="col-lg-6">
<div class="form-group">
<label>Password <span title="required">*</span></label>
<input type="password" class="form-control password" id="pw" name="password" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Confirm Password <span title="required">*</span></label>
<input type="password" class="form-control password" id="confirm_pw" name="confirm_password" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Tax ID <span title="required">*</span></label>
<input type="text" class="form-control" name="tax_id" value="<?php echo isset($_COOKIE['register_tax_id']) ? $_COOKIE['register_tax_id'] : ''; ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Upload presale permit certificate:<span title="required">*</span></label>
<input type="file" class="form-control" name="fileToUpload" id="fileToUpload" required>
</div>
</div>
</div>
<p>*Note: You must have an order with a minimum of $200.00 to checkout.</p>
<button type="submit" class="btn green--btn" id="registerbtn" name="register">Register</button>
</form>
Array Result using Print code
[file_upload] => Array ( [0] => apartment.png )
PHP Code
if (isset($_POST['register'])) {
// $username = explode('#', $_POST['email']);
// $username = $username[0];
$username = $_POST['username'];
$user_data = array(
'first_name' => $_POST['firstname'],
'last_name' => $_POST['lastname'],
'user_email' => $_POST['email'],
'user_login' => $username,
'nickname' => $username,
'user_nicename' => $username,
'user_pass' => $_POST['password'],
'role' => 'pending_wholesale_customer'
);
$user_id = wp_insert_user($user_data);
if ( is_wp_error($user_id) ) {
setcookie("register_error", $user_id->get_error_message(), time() + (60 * 5), '/');
foreach ($_POST as $key => $value) {
if ($key != 'confirm_password' && $key != 'password') {
$cookie_key = 'register_' . $key;
setcookie($cookie_key, $value, time() + (60 * 5), "/");
}
}
wp_redirect( 'new-account-registration' ); exit;
} else {
unset($_COOKIE['register_error']);
setcookie('register_error', '', time() - 3600, '/');
foreach ($_POST as $key => $value) {
unset($_COOKIE[$key]);
setcookie($key, '', time() - 3600, '/');
}
}
update_user_meta($user_id, 'billing_company', $_POST['company']);
update_user_meta($user_id, 'billing_address_1', $_POST['address']);
update_user_meta($user_id, 'billing_city', $_POST['city']);
update_user_meta($user_id, 'billing_state', $_POST['state']);
update_user_meta($user_id, 'billing_postcode', $_POST['zipcode']);
update_user_meta($user_id, 'billing_phone', $_POST['phone']);
add_user_meta($user_id, 'user_tax_id', $_POST['tax_id']);
add_user_meta($user_id, 'file_upload', $_POST['fileToUpload']);
$creds = array();
$creds['user_login'] = $_POST['email'];
$creds['user_password'] = $_POST['password'];
$user = wp_signon( $creds );
wp_redirect( 'registration-confirmation' ); exit;
}
Here's to show the value of file upload I know this one is already a file name, but I can't see the attachment file on the array code.
echo esc_html( get_the_author_meta( 'file_upload', $user->ID ) );
I want to play with this fields,i want to insert description1,description2 data into this description[] how to do that i tried but something is missing.
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description[]" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 1 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description2" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 2 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description3" placeholder="Enter description">
</div>
</div>
public function store(Request $request)
{
$description1 = $request->input('description1');
$description2 = $request->input('description2');
$products = new ProductAdd;
$prodduct->name = $request('name');
$prodduct->description[] = [
'description1' => $description1;
'description2' => $description2;
];
$product->save();
}
If you cast the description field to be an array in your model, you can update your controller code to:
$prodduct->description = [
'description1' => $description1;
'description2' => $description2;
];
To cast the field to an array, add this to your ProductAdd Model:
$casts = [
'description' => 'array'
];
I am trying to log a user in and take them to a page that displays content based on a slug.
I get this error :
ErrorException in ApplicantLoginController.php line 21:
Missing argument 2 for App\Http\Controllers\Auth\ApplicantLoginController::Login()
This is my controller :
public function Login(Request $request, $slug){
//Validate the form
$this->validate($request, [
'email' => 'required',
'password' => 'required',
'agree' => 'required'
]);
//Attempt to log the user in
if (Auth::guard('applicant')->attempt(['email' => $request->email,'password' => $request->password] )) {
$house = House::where('slug', '=', $slug)->first();
return view('client.index')->withHouse($house);
}
return redirect()->back()->withInput($request->only('email'));
}
This is the route to the page I am taking them to after login :
Route::get('client/index/{slug}', ['as' => 'client.index', 'uses' => 'ClientRegistrationController#index']);
This are my login routes :
Route::get('client/login', 'Auth\ApplicantLoginController#ShowLoginForm')->name('client.login');
Route::post('/client/login', 'Auth\ApplicantLoginController#Login')->name('client.login.submit');
Any ideas on how I can solve this problem?
This the button that takes the user to the page with the content based on a slug
Book now
If the user is not logged in the page redirects to this login page:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit') }}">
<input name="_token" type="hidden" value="{{ csrf_token()}}"/>
<div class="form-group">
<label for="email" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="email" class="form-control" placeholder="Your Email" name="email" required="">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="password" class="form-control" placeholder="Password" name="password" required="">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="agree" required=""> I have read and accepted the terms and condition
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-3">
<input type="submit" value="Login" class="btn btn-primary">
</input>
<a class="btn btn-link" href="#">
Forgot Your Password?
</a>
</div>
</div>
</form>
You should have $slug declared in the post route:
Route::post('/client/login/{slug}', 'Auth\ApplicantLoginController#Login')->name('client.login.submit');
And change your form to add the parameter:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit', ['slug' => $slug]) }}">
I'm trying to create a Twitter Bootstrap based horizontal form using Symfony and the Braincrafted Bootstrap module. I've copied the example from the docs however my form is not rendering correctly
My code is as follows
class MyController extends Controller {
/**
* #Route("/")
* #Method("GET")
* #Template
*/
public function someAction() {
$form = $this->createForm(new HorizontalFormType());
return array("horizontalForm" => $form->createView());
}
}
This class is taken from the docs:
class HorizontalFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('email', 'text', array(
'label' => 'Email',
'attr' => array('placeholder' => 'Email')
));
$builder->add('password', 'password', array(
'label' => 'Password',
'attr' => array('placeholder' => 'Password')
));
$builder->add('checkbox', 'checkbox', array('label' => 'Remember me'));
}
public function getName() {
return 'horizontal_form';
}
}
The template code is copied as well
<form class="form-horizontal">
<legend>Legend</legend>
{{ form_widget(horizontalForm, {'form_type': 'horizontal'}) }}
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
The resulting HTML for the form is
<form class="form-horizontal ng-pristine ng-valid">
<legend>Legend</legend>
<div id="horizontal_form">
<div>
<label class="required" for="horizontal_form_email">Email</label>
<input type="text" placeholder="Email" required="required" name="horizontal_form[email]" id="horizontal_form_email">
</div>
<div>
<label class="required" for="horizontal_form_password">Password</label>
<input type="password" placeholder="Password" required="required" name="horizontal_form[password]" id="horizontal_form_password">
</div>
<div>
<label class="required" for="horizontal_form_checkbox">Remember me</label><input type="checkbox" value="1" required="required" name="horizontal_form[checkbox]" id="horizontal_form_checkbox">
</div>
<input type="hidden" value="fea7c498a01aebd814baf4a9f57df4b6e3646195" name="horizontal_form[_token]" id="horizontal_form__token">
</div>
<div class="control-group">
<div class="controls">
<button class="btn" type="submit">Sign in</button>
</div>
</div>
</form>
Note I'm also using AngularJS in my project (hence why the ng directives are added to the form's class list).
What have I missed?
As described in the Getting Started guide in the "Form Theme" section, I had to manually configure Symfony to use the Braincrafted form template. It did not unfortunately automatically work.
twig:
form:
resources:
- "BraincraftedBootstrapBundle:Form:form_div_layout.html.twig"
For braincrafted-bootstrap up to v1.4, to make any form horizontal from within a twig,
{{ form(form, {'form_type': 'horizontal', 'attr': {'class': 'form-horizontal'}}) }}
"form-type" tells BC_Bootstrap to add the control groups for you, and the attr: class: then tells bootstrap css to apply the horizontal style. You need to have both of these applied.
This means that you don't need to extend any horizontal formTypes, nor break the form out into widgets et al in order to set the class. Just apply the form_type and class in the twig as above.
You must Wrap labels and controls in .control-group
All labels must have class .control-label.Input fields must be wrapped with div class="controls". The html output should be like this
<form class="bs-docs-example form-horizontal">
<legend>Legend</legend>
<div id="horizontal_form">
<div class="control-group">
<label for="horizontal_form_email" class="required control-label">Email</label>
<div class="controls">
<input type="text" id="horizontal_form_email" name="horizontal_form[email]" required="required" placeholder="Email">
</div>
</div>
<div class="control-group">
<label for="horizontal_form_password" class="required control-label">Password</label>
<div class="controls">
<input type="password" id="horizontal_form_password" name="horizontal_form[password]" required="required" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label for="horizontal_form_checkbox" class="checkbox required">
<input type="checkbox" id="horizontal_form_checkbox" name="horizontal_form[checkbox]" required="required" value="1"> Remember me
</label>
</div>
</div>
<input type="hidden" id="horizontal_form__token" name="horizontal_form[_token]" value="def76ca43f623d0a4ad8145e39f33907b7e9e0a1"></div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
I'm trying to add attributes to my rendered radios
$builder
->add('myRadios', 'choice', array(
'choices' => array(
'one' => 'uno',
'two' => 'due'),
'multiple' => false,
'attr' => array('class' => 'testClass'),
'expanded' => true
the output is:
<div class="control-group">
<label class="control-label required">Myradios</label>
<div class="controls">
<label for="form_one_0" class="required radio">
<input type="radio" id="form_one_0" name="form[one]" required="required" value="uno" />
<span>Uno</span>
</label>
<label for="form_two_1" class="required radio">
<input type="radio" id="form_two_1" name="form[two]" required="required" value="due" />
<span>Due</span>
</label>
</div>
</div>
no references to class='testClass'
I can't find any issue online
Try this way Adam,
$form = $app['form.factory']->createBuilder('form')
->add('myRadios', 'choice', array(
'choices' => array(
'one' => 'uno',
'two' => 'due'),
'multiple' => false,
'expanded' => true,
'attr' => array('class' => 'testClass'),
))
->getForm();
it works:
<div id="form_myRadios" class="testClass">
<input type="radio" id="form_myRadios_0" name="form[myRadios]" required="required" value="one">
<label for="form_myRadios_0" class="required">uno</label>
<input type="radio" id="form_myRadios_1" name="form[myRadios]" required="required" value="two">
<label for="form_myRadios_1" class="required">due</label>
</div>
How does your twig code look like? And which form template do you use?
You use a custom form template because
<div class="control-group">
<label class="control-label required">Myradios</label>
<div class="controls">
is definitely not standard Symfony!