View app
I made a multi update row with js ... the button function uses put to retrieve the id of each row ...
this success but..
I want to add input form for data that is updated
I don't know what to do
<form action="{{ url('UpdateAll') }}" >
<input type="text" name="name" placeholder="test">
<input type="submit" class="btn btn-primary delete_all" value="Mass Update">
</form>
code detail
I just had a look at your code in the link provided. Is it because your ajax request PUT url is set to :
url: $(this).data('url'),
But you're not actually setting that URL on your input? eg.
This:
<input type="submit" class="btn btn-primary delete_all" value="Mass Update">
Should be:
<input type="submit" class="btn btn-primary delete_all" value="Mass Update" data-url="/your-put-url-here">
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm very new to Ajax, so this is my first try to bind laravel and Ajax together. Anyway I've understood what it's all about and everything, but when I try to post data using a submit button, the data is delivered as a get method, it's as if the code never gets to the ajax function.
Here is My form :
<form id="addtocart">
<button class="btn btn-outline-primary btn-lg" type="submit">add to cart</button>
<input id="name" type="hidden" value="{{$one->name}}" name="data">
<input id="price" type="hidden" value="{{$one->price}}" name="price">
<input id="image" type="hidden" value="{{$one->image_path}}" name="image">
</form>
My Ajax Function :
jQuery(document).ready(function(){
jQuery('#addtocart').submit(function(e){
e.preventDefault();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
jQuery.ajax({
url: "{{ url('/addtocart') }}",
method: 'post',
data: {
name: jQuery('#name').val(),
image: jQuery('#image').val(),
price: jQuery('#price').val()
},
success: function(result){
jQuery('.alert').show();
jQuery('.alert').html(result.success);
}});
});
});
Thanks for your help !!! (I thought that the script wasn't running at first because I was including the jquery library after the ajax function .. But that wasn't the case)
Insert method="post" inside form tag
<form id="addtocart" method="post">
<button class="btn btn-outline-primary btn-lg" type="submit">add to cart</button>
<input id="name" type="hidden" value="{{$one->name}}" name="data">
<input id="price" type="hidden" value="{{$one->price}}" name="price">
<input id="image" type="hidden" value="{{$one->image_path}}" name="image">
</form>
Hope it will be work
Why don't you add an id to your button
<button id="addtocart" class="btn btn-outline-primary btn-lg" type="submit">add to cart</button>
and then assign the event listener to the button click instead:
jQuery('#addtocart').on('click', function(e){}); // the closure body should be the same.
In your form tag, assign the action attribute to a hashtag value.
<form id="addtocart" action="#">
<button class="btn btn-outline-primary btn-lg" type="submit">add to cart</button>
<input id="name" type="hidden" value="{{$one->name}}" name="data">
<input id="price" type="hidden" value="{{$one->price}}" name="price">
<input id="image" type="hidden" value="{{$one->image_path}}" name="image">
</form>
Without it, the form will execute traditionally first, thats why the ajax script isn't catching the submit function.
What I want to do is very simple: I want to create a form using Code Igniter's form helper and place other buttons (aside from the submit button) within the form. Let me illustrate using this snippet (not my actual form):
<?php echo form_open('client/send_message'); ?>
<input type="text" name="message" required />
<button class="btn btn-primary btn-block">Send</button>
<button class="btn btn-default btn-block" data-toggle="modal" data-target="#my_modal">Send Email</button>
<?php echo form_close(); ?>
The second button Send Email is supposed to open a modal. The problem is this, clicking the Send Email button also processes the form. So it appears you cannot have more than one button within the same form. I know I can have the Send Email button outside the form but my original form has several buttons in different places within the form and placing them outside the form will break the design. I also know that I can use <input type="button"> within a form, but I really want to know the reason for this behavior and if there's a solution to it.
Thanks!
Hope this will help you :
change the type of button form submission change to submit
<?php echo form_open('client/send_message'); ?>
<input type="text" name="message" required />
<button type="submit" class="btn btn-primary btn-block">Send</button>
<button type="button" class="btn btn-default btn-block" data-toggle="modal" data-target="#my_modal">Send Email</button>
<?php echo form_close(); ?>
It would be better to use the a tag for this purpose.
<?php echo form_open('client/send_message'); ?>
<input type="text" name="message" required />
<button class="btn btn-primary btn-block">Send</button>
Send Email
<?php echo form_close(); ?>
<input type="button"/>
This will not submit the form, as we have specified it to act as a button only.
<input type="submit"/>
This will submit the form, as we have specified it to act as a button to submit a form.
I'm wanting to use a button element rather than input on the woocommerce login form, purely for styling reasons. So rather than
<input type="submit" class="btn btn-outline-primary" name="login" value="Login" />
I want to use
<button type="submit" class="btn btn-outline-primary">Login</button>
This doesn't work though and I've no idea why.
Just found it out the button element need the value setting the same as the input i.e.
<button type="submit" class="btn btn-outline-primary" name="login" value="Login">Login</button>
i have the following button:
<form method="GET" action="/cms/deleteBlog/">
<input class="btn btn-danger btn-small" type="submit" name="'.$blogID.'" value="Delete">
</form>
So right now i get the following url:
cms/deleteBlog/?1=Delete
obviously i want something like the following:
cms/deleteBlog/id=1
So i tried the following (which is obviously not working):
name="id='.$blogID.'"
So how do i solve this? i've been looking around on the internet, and i know the solution is quite easy. But i just can't remember the way how it is done!
Add a hidden form field.
<input type="hidden" name="id" value="1" />
Also, you should never use GET to delete or modify data. Read Why should you delete using an HTTP POST or DELETE, rather than GET? for insight.
Why not use a hidden input field, e.g:
<form method="GET" action="/cms/deleteBlog/">
<input type="hidden" name="id" value="'.$blogID.'">
<input class="btn btn-danger btn-small" type="submit" value="Delete">
</form>
Or, if you want pretty URLs:
<form method="GET" action="/cms/deleteBlog/id='.$blogID.'">
<input class="btn btn-danger btn-small" type="submit" value="Delete">
</form>
I have never really used radio buttons before. So what I am trying to achieve is, using two radio buttons 'Public' and 'Private'. This is for the user's profile. My HTML code for the buttons is;
<div class="btn-group" data-toggle="buttons-radio">
<button type="button" class="btn btn-primary" id="privacy" name="privacy" value="0">Private</button>
<button type="button" class="btn btn-primary" id="privacy" name="privacy" value="1">Public</button>
</div>
As for the PHP, I'm not sure how to get the value and store it. Any help is appreciated!
Use a form.
<form method="get" action="yourscript.php">
<input type="radio" id="private" name="privacy" value="0">
<label for="private">Private</label>
<input type="radio" id="public" name="privacy" value="1">
<label for="public">Public</label>
<input type="submit" value="Save">
</form>
Change your buttons to input elements, which, together with the form, provide a HTML native way to send data to a script without the need for Javascript (although you can use Javascript to enhance the usability later on).
Using the label tag, you can assign a text to a radiobutton. This allows this text to be clicked as well, and it also provides better support for screen readers, because they can actually see which text belongs to the radiobutton.
An id needs to be unique, so I changed it to private and public. The ids are also used to link the label to.
The name determines by which name the value is sent to your script.
In PHP, you can use the superglobal $_GET. $_GET['privacy'] will contain '0' or '1' depending on the choice made. If the method of the form was post, you could use the superglobal $_POST instead, or you can use $_REQUEST, which contains values from either, so in that case your script doesn't care whether the values were send in the url (get) or in the chunk of invisible post data that is sent along with the request.
change type to radio and donot use the same id for morethan one element id is supposed to be unique
Also when you post the form type=button values will not be passed with the form
<div class="btn-group" data-toggle="buttons-radio">
<input type="radio" class="btn btn-primary" name="privacy" value="0"/>Private
<input type="radio" class="btn btn-primary" name="privacy" value="1"/>Public
</div>
assuming its posted on $_POST['privacy'] should contain either a 1 or a 0
also dont use an ID twice - they are supposed to be unique
You don't have form and submit button.
HTML page:
<div class="btn-group" data-toggle="buttons-radio ">
<form name="privacyForm" action="action.php" method="post">
<button type="radio" class="btn btn-primary" name="privacy" value="0">Private</button>
<button type="radio" class="btn btn-primary" name="privacy" value="1">Public</button>
<input type="submit" value="Submit">
</form>
</div>
action.php
<?php
echo $_POST['privacy']; // should be 0 or 1
?>
i have assumes that your form is something as follows.
<form name="sample" action="form_submit.php" method="POST">
<div class="btn-group" data-toggle="buttons-radio">
<input type="button" class="btn btn-primary" id="private" name="privacy" value="0">Private</input>
<label for="private">Private</label>
<input type="button" class="btn btn-primary" id="public" name="privacy" value="1">Public</input>
<label for="public">Public</label>
</div>
<input type="submit" name ="submit" value ="Submit"/>
</form>
you can use the following code inside the action (form_submit.php) to get the selected radio button value.
form_submit.php
<?php
$selected_radio = $_POST['privacy'];
print $selected_radio;
?>
make sure that you are not duplicating the IDs because they should be unique.