Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an edit form with the url looking like localhost/edit-form/*code* The code is a random 16 long string. What I would like to do is when submitting the form, refresh the page showing the form again with the new values.
I have tried to redirect with an extra attribute like localhost/edit-form/*code*/message which returns an error saying page not found.
I have also tried something like localhost/edit-form/*code*?message=1 but message isnt available to get via $_GET.
My goal is just to have a div alert saying "form edited" after the page is refreshed.
Flash messages are usually stored in $_SESSION. You could create a custom method that...
Stores the message to the session.
Deletes the message from the session, as soon as it is displayed for the user.
You could then call the method in your template file as soon as the user is redirected to it.
After your operation you can store message is $_SESSION['mesaage']
If this variable is set then you can display the message. As an oddon you can store success and failure class in separate session variable and display with success or failure class.
Once text is displayed you can unset sessions.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to protect my PHP files from direct access, but my problem is that i do not include them in my index. I use jquery load() or iframe, so basicly the php files in include folder don't have access or code from index.php. So i tried with define CONST, but of course didn't work... So basicly i have URL site.com/file witch i load in my index with jquery load as a pop up, but i don\t want if someone try to access it directly from browser to have access... Any idea how should i protect them?
Mike's answer works for regular users, but if you need to be sure that the user first loads the index page, you could do something like:
generate a token when user loads index.php
add token to session data
add token to jquery load as a query parameter (e.g. site.com/file?token=xxxx)
on file load, compare token passed as parameter to the one stored in session and clear the session, so it cannot reuse the token
This way, the user is required to load index.php before loading file.
It wouldn't prevent an advanced user from acessing the file page directly after having the token.
try this, first block limits access to ajax requests, second one checks referring url is mywebsite
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){
echo "<span class='error_msgh'>Error 1. Process Aborted.</span>";
die();
}elseif(!preg_match('/(www.mywebsite.com)/', $_SERVER['HTTP_REFERER'])){
echo "<span class='error_msgh'>Error 2. Process Aborted.</span>";
die();
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there any way to generate webpages dynamically.for example I have a website called abc.com in which I have included a form with many fields.
When a user submit this form,I want a new webpage abc.com/xyz to be created.Wondering if this is possible.
Of course it's possible. Anything is possible in programming/development.
See the following PHP manual for a good tutorial: http://www.php.net/manual/en/domdocument.savehtmlfile.php
This is possible in variety of ways.
You can pass GET variables in URL (example.com/page?var1=1&var2=2) and use this variables to generate unique page by predefined template.
If you don't want to use variables in URL, you can POST them to page via form request or ajax call.
Alternatively you can use .htaccess configuration files to rewrite your URL and use url segments as variables (example.com/var1/var2), this is common approach in MVC systems, where first/second variables are class/method names.
So here's an example:
You have a page.php where form resides.
User fills a form and submits it.
Form goes trough AJAX call, submitting it to request.php page
request.php parses it and stores it in DB, generating unique id
AJAX event recieves from request.php a unique id and redirects user to review.php
with url (example.com/review/uniqueID) or (example.com/review.php?uniqueID)
review.php recieves uniqueId, get's info from DB by it and displays requested info
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a simple page that shows 4 different divs, all with a <h1> title (or other tag that shows text) and a form (with 1 input text) and a submit button... so far so good.
My answer is simple: I am looking for a way that:
when the user inserts a text and submit the form, the <h1> title shows the text that the user wrote
the form disappear (or takes style display:none)
this will take effect even if I refresh the page or view page in a different computer (probably need to save the data in a DB)
restart this process from the beginning (even if I need to code again).
This is for a mini game to provide to users 4 different choices and, if the user A select option 1, the <h1> will show text something like "User A was the first to choose this option. Please select a blank option" and, after the 1st raw over (point 4 described above), restart all forms.
NOTE: I am not asking in the way to "please do the code for me". I also searching for a way to store data in <php ?> - finding redbeanphp project.
I am also a newbie in SQL (just started to study SQLi last month to android development). My question is ONLY to looking for the best way to do this and what I need.
This would be the workflow:
When you click a button to submit the form JavaScript will send the form data to the server as an AJAX request and wait for a response from the server.
The PHP code on the server will read the data from the AJAX request and save it in a database and echo a success response along with the text to display.
Your JavaScript will receive this success message and hide form from the DOM and display the text in the header.
If you want the data to persist on the page on reload then you can save a flag in PHP session. Sessions persist in until you close browser window.
4.1 Use another AJAX call remove the flag from the session and reload the content.
So, if you are good with HTML and CSS you need:
JavaScript, AJAX, a JavaScript library to make things easier such as JQuery.
A server side language such as PHP.
A database to persist data. There are many choices. I am going to recommend MySQL just because there so many tutorials for it out there.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm wondering how to differentiate different submit and forms to a certain php function.
Currently I have 2 forms in my page, but each submit button will do 2 different thing.
I've tried using ISSET to control the submit but if failed, it always refer back to the same function.
Initially what I want to do is I wanna have the user to key in some verification info and submit the info to the database to do some checking (the data is in the database) and update the result on the same page, then only they proceed to submit the whole updated form to the payment gateway.
Assign a name to your submit button like
<input type="submit" value="Update" name="first_form" />
<input type="submit" value="Update 2" name="second_form" />
So, now you can execute a particular code like
if(isset($_POST['first_form'])) {
//Process first form
}
if(isset($_POST['second_form'])) {
//Process Second Form
}
I just read your question again, not getting much, but it seems like you want to carry values to another form or you want to show forms only if the first form is completed, so the best way to do this is to have a session var, which will hold the users form data, so that you can carry it on another page, also you can set flags from which you can show particular data to the user, for example, if user completes form 1 set $_SESSION['completion'] = 1 so you can use a condition to check whether session var isset, and if it is, whats the value and show the content to the user accordingly.
Due to the fact that PHP is a server side language, it only runs when the page loads. If you want information on the screen to change without reloading the page, you will probably need to use Javascript or Ajax.
if you use 2 form on basic html page, that wont do, because once it submitted, the page reloaded..
ajax is the aswers..
var dataSet={ SERIALIZE_VALUE FROM FORM1 };
$.post(URL_TO_PHP_ACTION_SCRIPT,dataSet,function(data){
// check the return value here if its valid, then enable the 2nd form for submitting
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm wondering which way is right to handle the errors in CodeIgniter and specifically the MVC pattern. I'm not talking about only sql errors, but lets say that you have user level-access control system and every level can access specific parts of the site.
What if somebody try to enter in a forbidden place for his level?
Or if you execute a controller based on some conditions and these conditions are not met?
Which is the best way to control the errors without confusing the end user which is browsing and using the application?
I'm wondering how you do it.
Do you use different views and controllers when an error occurs or something else?
You are asking 2 different things.
First one:
but what if you have a form which edits something, but according to user-level you cant edit.
You can achieve this but not showing the fields in the form nor updating the database if the user doesn't have permissions.
if ($user_has_permissions)
{
echo form_input('field_name');
echo form_input('field_name');
}
and when updating the row
if ($user_has_permissions)
{
$this->db->set('db_field_name', $field_name);
}
If you want to show an error message in form validation, use callbacks (callbaks in CodeIgniter).
Check if the user has permissions and show the message if hasn't.
Second one
Using die() is not an option, I just dont wanna crash my whole app
If you wan't to stop the execution without using die(), you have some other "friendlier" forms to do it:
show_404();
show_error();
show_error('Description of your error');
This will stop the execution and will show a fancy screen with the error description.
You could specify the user's access level in your database. If a user tries to access a forbidden place you could store some error in the userdata and display them in the view if its set.
The codeigniter session class documentation: http://ellislab.com/codeigniter/user-guide/libraries/sessions.html