I'm doing a questionnaire (form) and I need to put a submit button that does two things:
Be a button type INPUT (because I need to use this kind of button on my PHP code, I've if(#$_POST['Next']) for save the dates of the form in my DB).
That this button will have a link for go to the next screen of the questionnaire. I tried with
<a href="demo2.html" target="_blank">
<input class="buttonNext" name="submit" type="submit" value="NEXT ←">
</a>
This code doesn't work, but with IE browser, on the page appears a circle next to my button that is the link. So the button doesn't work; it only saves the data, but doesn't link to the next page.
How can I solve it?
The form's action determines the URL where the form is sent, and this is just good for you (it is sent to the PHP that processes this step). It can save the data and/or return the form again to show validation errors. Once you decide to go to the next step, you can redirect the user to that url.
use if(isset($_POST['Next'])){ instead of #
Related
I have a script that I downloaded and want to add an href="#" to it but it's interfering with the form on the page. The form is triggered by a button, not sure of that matters. I tested my href outside the form but it still refreshes the page once before it works. Here is the code.
<form method="POST" action="/profile/save_profile_setting">
Update My Location
</form>
<button class="btn" type="submit" name="action" ><span><?php echo __( 'Save' );?></span></button>
My href just passes the id to run ajax to find a location, it's always worked but now the two aren't playing well together. I have the same href on a different page by itself and it works fine.
Thanks for any help.
I didn't understand what is your actual query. I understood roughly of your query. My understanding for your question is that: with tag, you want to execute ajax call and with button, you want to perform form action. Based on this assumption:
(1) If you want to avoid page refresh with tag, you need to do as follows:
Update My Location
Now, you can easily perform ajax with tag.
(2) To perform button action with form, you need to add button inside form instead of outside the form.
i have main page and form this page there is some button "each button will refer the user to the correct page after click on it" i want to use PHP to prevent user from writing the URL manually also i used $_SERVER['HTTP_REFERER'] but it's not working with all browsers.
You can try to achieve it in this way:
on every page looking for some $_POST value, for example if (isset($_POST['refer']))
if isset the value that you're looking for print the page content, otherwise print error, redirect to homepage or do what you want to do when the user come in the page without clicking on your button
modify your button, on click not only redirect the user but submit a form with the wanted post value
You can add your value directly into button value
<form action="/yourpage.php" method="post">
<button name="subject" type="submit" value="VALUE_TO_SEND">BUTTON
TEXT</button>
</form>
VALUE_TO_SEND can be: the current url, or what you want to use to check the refer
I'm building a website in which the user can create articles with multiple images.
I would like to let the users while editing the form to can delete some image that they want. So I want to have in my form the main submit button that execute the function that store all details of article but also to I have another submit button that execute the function that delete the image.
How can I do that?
Thank you so much for your attention and participation.
If I got you right, you want 1 FORM, 2 SUBMIT buttons, and based on which one you press, do a different action? It is possible to do this, but not very practical.
To do it, create 2 submit buttons with each a value. I.e.:
<input type="submit" name="mysubmit" value="delete image" />
<input type="submit" name="mysubmit" value="send the form" />
when doing this, your post/get data will contain one item names mysubmit with the value, so you know which button was pressed, and you can do an action based on this.
However, when you submit a form by pressing a submit button, you do send the whole thing to your server, and have a page refresh. I usually prefer to use Ajax for the simple operation. For example, I would remove the delete submit button and replace it a simple button. When pressed, send an Ajax call to tell the server to delete the image, and use DOM to delete the image in the browser DOM tree (usually jQuery). Note that you can also use Ajax to post the form, nicer interface, and no page refresh.
I wanted some input as to what the best way to handle this would be. I have a submit button and a normal button inside a form. I don't want to do a submit on my delete button for the form. Is setting a link outside of the button to carry over into another file using a $_GET parameter the best way here? Basically, take the GET parameter in the php file and if its true, then do my delete functionality. Is there a better way here?
e.g. <input type="button" value="Delete Item" />
GET requests should be used when accessing data (SELECT). POST requests should be used when modifying data (UPDATE, CREATE, DELETE). i.e. You shouldn't be using a GET request to delete a system resource.
I had a similar thing, and there where two methods I used:
The first was that I used a standard button which had the onclick attribute set to a javascript function that would change the value of a hidden input and would then submit the form.
The second was a submit button, but following this question: Position div box at the end of after ensuing elements, I had the main form submit (that would save) at the beginning of the form, which then appeared at the bottom of the form. This mean't that when if the enter button was pressed, the delete submit wouldn't be clicked (and detected by the script), but the main submit would be.
I'm using Generic HTML Form Processor in combination with an xampp lite installation to save data into a MYSQL database. However, I've encountered a problem while writing a multi-page survey. If users use the previous and forward buttons coded like:
<INPUT TYPE="button" VALUE="Previous Page" onClick="history.go(-1);">
<input type="submit" value="Go to last page">
The next button differs slightly per page. For example, on page 1 it's:
<input value="Next Page" type="submit">
Users can go back and forth in the survey. I would prefer them to use the backwards and forward button to let the browser take care of saving the data but sadly it's not an option. The next button is linked to a hidden input code like:
<input type="hidden" name="next_page" value="http://localhost/quislast.html">
It works like a dream except for one problem. Imagine there are three pages, A, B, and C. If a user is on page C, and they click the previous button twice so they return to page A. If they then click the next page button, the form data (radio buttons) that the users select on pages B and C are no longer remembered. The users then have to re-select their answers before submitting the form.
Any ideas? Thank you in advance. And I apologize if the answer is so simple a novice could understand it.
Use a Session to collect the data during the survey. Then, when the user goes back and forth through the pages, fill in the input value attributes from the collected values in the $_SESSION array. When the user is finished with the survey, save the data to the database.