how can i show a message box with PHP codes ? I seen this answer but i don't want to use JS code in php .
Something like this should do the job:
<?php
if (isset($_POST['submit']))
{
//data checks here...
//database stuff here...
echo '<div class="msg">'
.'YOUR MESSAGE IN HERE'
.'</div>';
}
?>
<style>
.msg {border:1px solid #bbb; padding:5px; margin:10px 0px; background:#eee;}
</style>
<form action="" method="post">
Name:<input type="text" id="name" name="name"/>
<input type="submit" value="submit" name="submit"/>
</form>
The message boxes you are referring to are created with either JS or HTML/CSS. Since you don't want to use JS, the only alternative is returning an HTML that contains the desired box. Keep in mind that the PHP executes on the server side and just returns a response for each request. Once the response is returned, the PHP is no longer executing.
There are several UI Kits with nice looking boxes. Bootstrap is one of the most popular and it's very easy to use. Check their getting started page to see how to add their CSS in your layout.
I think I found what you are looking for. You need to echo a div with some text inside, and also echo a checkbox inside your div. In your CSS you can check if the checkbox is checked and stylize it to disappear. The checkbox will act as your close button for the message.
See further information here.Toggling class without using JavaScript
Related
I made a form where user posts just links and text. No images and videos. I also did some kind of validations from server side in PHP. I also did very basic SQL INSERT for storing data in database. What I want is, that whenever user posts, it is always displayed on a website with different colors from database. I Googled it but got nothing. Any idea, or help on where to start?
Simple html form:
<form action="checkbox1.php" method="post">
<input name="name" id="name" type="text"/><br/>
<input type="text" id="name2" name="name2"><br/>
<input type="checkbox" id="checkbox" name="checkbox"><br/>
<input type="submit" id="submit" name="submit">
</form>
.postHolder:nth-child(5n+0) .post-text {
background: #8dc63f;
}
.postHolder:nth-child(5n+1) .post-text {
background: #009688;
}
.postHolder:nth-child(5n+2) .post-text {
background: #3f51b5;
}
.postHolder:nth-child(5n+3) .post-text {
background: #f44336;
}
.postHolder:nth-child(5n+4) .post-text {
background: #607d8b;
}
This example will work in your case, .postHolder is the class of the dive which will repeat for every post, and .post-text is class where you actually want to apply CSS, I have applied background color you can add whatever you want.
First of all, do you have predefined colors in the database?
if yes! Then you will need to send color as a parameter from the database using get or post method with your post.
Then you need to use that color and apply using javascript jquery or angular whatever your frontend is.
If you have colors in your stylesheet then you need to create predefined classes with different colors; apply them to your post dynamically.
But the second option is a bit clumsy and complex, always you will need to take which was last class you applied and then apply next class.
The third option is to use nth-child but this method has some limitations like you need to write a class for every child element.
I have a form table with checkboxes. I want the user to check whichever url (element) they want to delete, press a button which then calls a "delete.php" file which deletes that record in mysql.
What I am trouble finding out how to do is to call the delete.php file with a button outside of the form. I know that you would typically use a submit button inside the form but in this situation, I am exploring whether it is possible to do it with a button that is outside it.
An image is attached to illustrate why I want to do that. The url menu on the bottom is called by a function because I want it to be modular. So I think the "Delete BM" question needs to be able to action the deletion of the checked checkbox.
I have googled a variety of search cases which dont really answer my question:
How to send checkbox state through form in a table
Search "php how to call php file outside form"
Search "how to call php file without submit button"
Call php file without using form action
Submit without submit button
Use following code for submitting your form.
and use search keyword in google "submit form without submit button in php".
<form id="jsform" action="whatever you want">
// input fields
</form>
<script type="text/javascript">
document.getElementById('jsform').submit();
</script>
For Your Problem. Below are Sample code
<input type='checkbox' class='test' name='test' value='1'>
<input type='checkbox' class='test' name='test' value='2'>
<input type='checkbox' class='test' name='test' value='3'>
<input type='checkbox' class='test' name='test' value='4'>
is somthing your checkboxes then following is the script
<script>
$(function(){
$(".test").click(function(){
var checkBoxValue = $(this).val(); // value of checkbox
$.ajax(
{
url: "" // url of page where delete funcnality is written
// and id of field
})
.done(function(data)
{
// success
});
});
});
</script>
In the past I have come across this sort of issue, of wanting a submit button outside of a form for layout/presentation reasons.
Having given it some thought and reading around, I learned there were some very good reasons to avoid doing so;
Changing the default behaviours of the browser is generally a bad idea, you make extra work for yourself and in the end is likely to complicate things and often also lead to confusing users. (for example: what happens if user clicks enter, will it still submit the form?)
Users that do not have up to date javascript or do not have it switched on, will not be able to use your form / site.
You can achieve what you want and still use the standard html submit button. Using CSS to make it appear as a text link, great example;
How to make a submit button display as a link?
In your example I personally would just have the submit button appear as a button (styled to match sites design) directly under the checkboxes, separate from your menu below. As this makes the most sense to me, and would save you some work as you wouldn't need to fiddle with your menu function.
However if you wanted to achieve exactly as you set out, you could pass the button (html string) as a paramenter into your function so that it can be entered into the menu list, then return all the menu html string and print it inside your form;
<form>
<input type="checkbox" name="1" /><br />
<input type="checkbox" name="2" /><br />
<input type="checkbox" name="3" /><br />
<?php
$buttonHtml = '<input type="submit" name="delete_bm" value="delete bm" class="submitLink" />';
echo navMenu($buttonHtml);
?>
</form>
Now the submit tag is within the form tag (and will behave as as intended), it is simply a case of using CSS to style these and any other elements to give you the presentation that you desired (might need to remove padding, margin etc. from form element).
.submitLink {
font: inherit;
background-color: transparent;
text-decoration: underline;
border: none;
color: blue;
cursor: pointer;
}
.submitLink:focus {
outline: none;
}
form{
padding: 0;
margin: 0;
}
The big upside is that now you do not need any un-necessary javascript, giving maximum accessibility and maintaining the functionality that users expect.
Also feels less complicated to me and that it is less likely to need updating.
Side note: if your form allows users to delete multiple bookmarks at once (seems like it should) you might want the text on the button to read; delete bookmark(s) Hope you had considered that ;)
You can use jQuery AJAX for this.
Because, calling PHP script with form submit will cause total page refresh.
you need to just delete the selected checkbox row and delete the entry from database.
I will explain the pseudo logic for it.
On click of the link Delete BM, call javascript for AJAX.
First open a confirm dialog.
Through AJAX, pass the id to be deleted to backend PHP file.
In PHP file, write the code to delete the record.
If record gets deleted, echo success there else failure.
If in AJAX, we get results success, delete the respective rows.
jQuery $.ajax()
I got two forms.
First form contains a button which will mark the task done and retrieve a new task.
Second form is for submitting translated content or work on already saved content.
So it contains a textarea and a save button.
PHP + Mysql will output already saved work in the form if anything exists.
I want to make the Task Done button unavailable in the first form, if the textarea in the second form is edited and the Task done button should appear after the save button have been pressed but I am not sure what the best way is to solve this problem.
I think the best solution will be Jquery but I am no expert.
Use a combination of CSS and Javascript manipulation.
Live preview
HTML
<form action="" method="POST">
<button id="btnTaskDone">Task Done</button>
</form>
<form action="" method="POST">
<textarea name="task" cols="20" rows="5">...</textarea> <br />
<button id="btnSaveTask">Save</button>
</form>
CSS
#btnSaveTask {
background: orange;
}
#btnTaskDone {
background: blue;
display: none; /* This part is the important part */
}
jQuery
$('#btnSaveTask').click( function(btn) {
$('#btnTaskDone').show();
});
I am using the code below:
<form>
<textarea cols="50" rows="4" name="link"></textarea>
<textarea cols="50" rows="4" name="notes"></textarea>
<input type="submit" value="Submit">
</form>
It creates two text boxes and I was wondering how to get them from this into a different html file's body code? I think I would need PHP.
At the end I would just want it to display a message saying "Complete" and in a html file e.g code.html in the tags it would have the contents of the two text boxes seperated by one line.
Regards!
Sounds like you would need PHP to receive the data.
See this for a basic form that posts to a PHP page.
you most use php html like this:
echo '<form id="form1" name="form1" method="post" action="">'.
'<p>PASWORD<br>'.
'<input type="text" name="name0" id="text" /><br><br>'.
'<p>BACKLINK<br>'.
'<input type="text" name="name" id="text" />'.
'<br>;'.
'<input type="submit" name="Enter" id="Enter" value="Enter" />'.
'</form>';
and use if for run html
if ($_POST['name0']>''){
your code
}
To accept input one one page and display it on another will require PHP. The general idea:
The HTML form page:
Contains you HTML form where the user enters and submits their input. The data from the form is sent to the PHP processing script. We'll assume you use the POST method.
The PHP processing script:
Contains code to read the POST values and sanitize them. This means you want to check for HTML you don't want, script tags, etc - anything you don't want. In this case, the user will be displaying this code to themselves, so they can't really harm another user. However, it's something important to keep in mind. The rule of thumb - never trust user input - always check it and clean it. Now that the PHP script has read and cleaned the data, you want to display it.
The PHP display script:
Contains the HTML of the page and PHP code to display the values you captured in the PHP processing script.
Other notes:
The PHP processing and display scripts can live in the same file. You will have to process before you display. Alternately, you can run the processing script and then include the display script. Both will work.
I'm new to PHP but was wondering how this can be done.
I want to have submit an HTML form to another PHP page, but i dont want to use the ugly button. I want to use a link.
The thing is, i see many solutions out there that uses Java Script/Jquery etc to solve this, Does any one know how to do this with PHP code and HTML only?
Either use a <input type="submit"> and style it like a link with css, or create a Link with onclick:
Lol Rofl
If you want to make sure it works when JS is disabled, add something like this:
<noscript>
<input type="submit" ... />
</noscript>
This will show the button on computers where JS is disabled, the link above will still be shown. A workaround is to hide the link with CSS and then show it with JS..
You can do this way:
Submit
That will submit the form to whatever url set in the action attribute of the form.
I dont know how much Buttons are capable of being styled in a uniform way across all browser, but here is a start/proof of concept you can fiddle with, read: test, adjust, put into external CSS, and so on
<input type="submit" value="Send" style="
border:0;
background-color:transparent;
color: blue;
text-decoration:underline;
"/>
I found an alternative way of using plain text as a submit button, by trial and (a lot of) error. Put label tags around the submit button and the text, then define the button CSS so it doesn't display and the text CSS so it looks like a link.
Bear in mind that this is probably not good practise at all. :)
For example, this goes in the HTML form:
<label class="notalink"><input type="submit" value="Submit" class="invisibutton">
Click this text to submit</label>
And this goes in the CSS:
.invisibutton {
height: 1px;
width: 1px;
display: none;
vertical-align: text-bottom;
}
label {
color: (link-color)
text-decoration: (etc.)
}
And so on for the label definition so it looks like a standard link. The button is invisible but the text is clickable as its label, so it acts like a button.
The one downside is that it made my label text drop a pixel. If there were other words around the pseudo-link, I had to define the surrounding text class with a "vertical-align: bottom;" to make sure it didn't look weird.
Worked a charm, though. I successfully used it in a WordPress page to create fake links that kick off php scripts (by setting $_POST).