Recently i use this function to hide the last numbers of osc_user_phone() in Osclass 3.6.1
jQuery
<script>
$(document).ready(function(){
$("#showPhone").click(function () {
$("#showPhone").hide();
$("#hidePhone").show();
});
$("#hidePhone").click(function () {
$("#showPhone").show();
$("#hidePhone").hide();
});
});
</script>
HTML
<?php _e('user phone'); ?> :
<span>
<a href="#" id="hidePhone" style="display: none;">
<?php echo osc_user_phone_mobile(); ?>
</a>
</span>
<span>
<a href="#" id="showPhone">
<?php echo substr(osc_user_phone_mobile(),0,-4).'XXXX'; ?>
</a>
</span>
Up here everything is ok. If complete the Phone Cell field in User profile is ok, the phone number show in item page.
If post a new ad, without account and complete the Cell Phone input, the phone number not showing in item page.
from item-post.php, problem is here (i hope)
<div class="control-group">
<label class="control-label" for="phoneMobile"><?php _e('Cell phone', 'infinity'); ?></label>
<div class="controls">
<?php UserForm::mobile_text(osc_user()); ?>
</div>
</div>
and from user-profile.php, the cell phone input:
<div class="control-group">
<label class="control-label" for="phoneMobile"><?php _e('Cell phone', 'infinity'); ?></label>
<div class="controls">
<?php UserForm::mobile_text(osc_user()); ?>
</div>
</div>
the same code that item-post.php
How do input field to work and when user posted new ad the phone number show in the item page?
In osclass 3.7.1 (bender theme) I managed to put the registered user phone into item-post.php
The code:
<?php if(osc_is_web_user_logged_in()) { ?>
<?php if (!$edit) { ?>
<div class="control-group">
<label class="control-label" for="phoneLand"><?php _e('Phone', 'bender'); ?>*</label>
<div class="controls">
<?php UserForm::phone_land_text(osc_user()); ?>
<p style="font-size: 0.85em; color:red;">* empty => <u>it will miss from all the listings !</u></br>* filled => <u>it will show in all the listings !</u></p>
</div>
</div>
<?php } ?>
<?php if ($edit) { ?>
<div class="control-group">
<label class="control-label" for="phoneLand">The <?php _e('Phone', 'bender'); ?></label>
<div class="controls">
<p style="font-size: 0.85em;"> can be edited here.</p>
</div>
</div>
<?php } ?>
<?php } ?>
When submitting the page, Osclass checks whether it's a registered user or a non-registered user that is publishing an item.
If it founds a user id, infos are stored in the oc_t_user that has a s_phone_land and s_phone_mobile.
When a non-registered user is publishing an item, his infos are stored into the oc_t_item table in the database. Unfortunately, it only saves the s_contact_name and s_contact_email, no field is available is this table for the phone.
Then, your phone input field is submitted but just not taken into account by the controller. You can see the process in controller/item.php and ItemActions.php.
You might want to look at the prepareData() method in ItemActions.php, around lines 1100 to 1110:
if( $userId != null ) {
$aItem['contactName'] = $data['s_name'];
$aItem['contactEmail'] = $data['s_email'];
Params::setParam('contactName', $data['s_name']);
Params::setParam('contactEmail', $data['s_email']);
} else {
$aItem['contactName'] = Params::getParam('contactName');
$aItem['contactEmail'] = Params::getParam('contactEmail');
}
$aItem['userId'] = $userId;
Related
Why I can't insert into 1 field to my database table?
I loop the data of my other table to display each data and put the result to href tag so it clickable and concatenate with it's id so it will put the id result after the link like this:
<a href="scheduling.php?CID=<?php echo $rows['docID']; ?>">
Here is how I loop my data using php on page1:
<?php
$sel = "SELECT * FROM doctors ORDER BY docID";
$result = $conn->query($sel);
if($result->num_rows>0)
{
while($rows = $result->fetch_array())
{
?>
<a href="scheduling.php?CID=<?php echo $rows['docID']; ?>">
<div class="doc_item" style="width:310px; border:4px solid #009973;display:inline-block; margin-top:40px; margin-right:20px;">
<img src="images/ft-img.png" style="width: 300px;">
<div class="item-lvl" style="width: 100%; background:#009973; color:#fff; height:70px; padding-top:10px;">
<h4 style="font-size:20px; font-weight:bold;">Dr. <?php echo $rows['docFname']; ?></h4>
<span><?php echo $rows['docType']; ?></span>
</div>
<div style="width: 100%; background:#00664d;padding-top:15px; padding-bottom:20px;">
<h3 style="color:#fff;">Make a Schedule!</h3>
</div>
</div>
</a>
<?php
}
}
?>
Then I want to add the value of CID to my database table using this code on page 2:
<?php
if (isset($_POST['btn-submit'])) {
$cusID = $customerID;
$docID = $_GET['CID'];
$checkupType = $_POST['checkupType'];
$schedTime = $_POST['schedTime'];
$contact = $_POST['contact'];
$ins = "INSERT INTO schedule
(customerID, docID, checkupType, schedTime, contact)
VALUE ('$cusID','$docID','$checkupType','$schedTime','$contact')";
if($conn->query($ins)===TRUE) {
header('location:success_sched.php');
}else{
echo "SQL Query: " . $ins . "->Error: " . $conn->error;
}
}
Now, this code insert data to my database table except $docID which is the value is $_GET['CID'];
docID column is intiger.
please correct my code, this is my school project.
Form code on page 2:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<div class="sign-u">
<div class="sign-up1">
<h4>Form of Checkup* :</h4>
</div>
<div class="sign-up2">
<label>
<input type="radio" value="Virtual" name="checkupType" required>
Virtual Checkup
</label>
<label>
<input type="radio" value="Facetoface" name="checkupType" required>
Face to Face Checkup
</label>
</div>
<div class="clearfix"> </div>
</div>
<p style="color:gray;">*Take note that virtual checkup will require a you stable internet for better communication.</p>
<div class="sign-u">
<div class="sign-up1">
<h4>Date and Time* :</h4>
</div>
<div class="sign-up2">
<input type="date" name="schedTime" id="date" required>
</div>
<div class="clearfix"> </div>
</div>
<p style="color:gray;">*Please provide Skype id as a contact information if <span style="color:#ff5c33">Virtual Checkup</span> is your choice.</p>
<div class="sign-u">
<div class="sign-up1">
<h4>Contact Information :</h4>
</div>
<div class="sign-up2">
<input type="text" name="contact">
</div>
<div class="clearfix"> </div>
</div>
<div class="sub_home" style="text-align: right;">
<input style="background: #339966;" type="submit" name="btn-submit" value="Submit">
<div class="clearfix"> </div>
</div>
</form>
Please understand that when you submit a form, that is a new request to the server. It has a new URL. Your page 2 form submits to $_SERVER['PHP_SELF']; - which is the current URL but without the querystring variables. Therefore your GET parameter is not passed in the form submit. (If you use the "View Source" feature of your browser to examine the "action" attribute of the form after it's rendered, you'll see exactly what URL it makes the request to when submitting. You can also see the same thing by looking at your browser's Network tool, or your webserver's access logs.)
There are a couple of ways around that, but I'd suggest adding the value as a hidden field in the form, and populating it with the value of the GET parameter during the previous request.
e.g.
<input type="hidden" value="<?php echo $_GET["CID]; ?>" name="CID">
and then in the PHP, retrieve it via $_POST like all the other variables:
$docID = $_POST['CID'];
Finally, please ensure you update your code to use prepared statements and parameters, as recommended in the comments, so that you are protected against both SQL injection attacks and unexpected syntax errors. You can get more info and examples here
I'm creating a form that needs to upload the information retrieved to an entirely separate site.
My form's "action" is to send the information to itself in order to validate information as well as see, if the required fields are input. If no errors are found, an email is sent with a message that includes the information from the form.
My code for the index page generally looks like this:
<?php include('action_page.php'); include('config.php')?>
<form method="POST" name="email_form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="row">
<div class="col-25">
<label for="subject"><span class="error">* <?php echo $titleErr;?></span> Subject <i class="glyphicon glyphicon-pencil"></i></label>
</div>
<div class="col-75">
<textarea id="subject" name="subject" placeholder="Please input a subject for the email" style="height:46px"><?php echo $title;?></textarea>
</div>
</div>
<hr>
<div class="row">
<div class="col-25">
<label for="emails"><span class="error">* <?php echo $emailErr;?>
</span> Email <i class="glyphicon glyphicon-envelope"></i></label>
</div>
<div class="col-75">
<p style="color:#0071c5">Please choose which group(s) to send this to:
</p>
<?php foreach($emails as $value): ?>
<input type="checkbox" name="email[]" value='<?php echo $value ?>'<?php if (isset($_POST['email']) && in_array($value, $_POST['email'])) echo 'checked="checked"';?> ><?php echo $value ?>     
<?php endforeach; ?>
</div>
</div>
My action page then sends an email using the php mail() function.
What I want to do is upload the body of the email on a separate website, which runs similarly to how Wikipedia is run - anyone can edit a page even if you're not the owner of the page.
To be honest, I'm not entirely sure how to even start. I'm able to use a header on my action page that can link my form to a different page, but this doesn't autofill like I want it to.
For example:
if(mail($mail_to, $title, $msg, implode("\r\n", $headers))){
header('Location: https://en.wikipedia.org/w/index.php?title=Japanese_aircraft_carrier_Ry%C5%ABj%C5%8D&action=edit');
}
sends the user to the appropriate Wikipedia page, but I'm not able to see any of my variables, that my form stored.
How do I solve the problem?
It's hard to say without seeing more of your code, but you will likely need API access to perform a POST request. Here is documentation from Wikipedia about working with their API in PHP.
This is the first application I do that has a DB and PHP, so I'll expect some errors on it, but I couldn't figure what I'm doing wrong with this one.
I'm trying to pass the username from a login HTML form using JS/JQuery, into a PHP file that will verify the username and will store the content from the DB into some $_SESSION variables.
In other words, I just want to verify some content from the login page, so I can assign a variable that will hold the entire session, until the user logout.
It works correctly in the login page and I can print the variables to the console, but when I redirect using JS to a second page, after the PHP user verification, but the variables appear empty in the second page.
In the research I did, I found that both pages should have:
<?php session_start(); ?>
But even after that change, the array $_SESSION is empty.
I also confirmed the status of the session:
<?php session_status(); ?> //This result in a 2, meaning that it's working.
And the ID is the same in both pages.
As this is a larger project, I wanted to be sure that anything else was bothering with this, so I've recreated this as a smaller project and I'm still having the problem. This is what I have in the files:
Index.php
I stripped as much as possible and to verify if the problem persisted.
Here is the PHP/HTML form and also the JQUERY script that overrides the button functionality to do what I need.
This is the begining of the file:
<?php session_start(); ?>
Then the BODY:
<body class="bg-light">
<div class="flex-row d-flex justify-content-center">
<div class="col-xs-12 col-sm-8 col-md-6 col-lg-4" >
<form class="card" method="post">
<div class="card-body">
<div class="form-group">
<label for="username">User</label>
<input type="text" class="form-control" id="username" placeholder="" autocomplete="username">
</div>
<div class="form-group">
<label for="pssw">Password</label>
<input type="password" class="form-control" id="pssw" placeholder="" autocomplete="current-password">
</div>
<div class="d-flex justify-content-between">
<button class="text-center btn btn-primary" id="btn-login">Enter</button>
</div>
</div>
</form>
<div>
This is the ID of the session: <?php echo session_id(); ?>
</div>
</div>
</div>
JQuery script
$(document).ready(function () {
$("#btn-login").click(function(){
event.preventDefault();
$.ajax({
url: "mylogin.php",
type: "POST",
data: {
name: $("#username").val(),
pssw: $("#pssw").val(),
},
success: function(data){
if (data == true){
$(location).attr('href', '/page2.php');
}
}
});
});
})
Mylogin.php
Here I got the variables from the JQuery script, verify if the user and password are 'a' and then assign the $_SESSION variables.
<?php
$rawUser = $_POST['name'];
$rawPssw = $_POST['pssw'];
if($rawUser == "a" && $rawPssw == "a"){
$_SESSION["username"] = $rawUser;
$_SESSION["another"] = "New Test";
echo true;
} else {
echo false;
}
?>
Page2.php
The purpose of this one is just to print the variables, but they are empty.
Again this is the first line of the file:
<?php session_start(); ?>
And then the body:
<body class="bg-light">
<section class="container" id="login">
<div class="flex-row d-flex justify-content-center">
<div class="col-xs-12 col-sm-8 col-md-6 col-lg-4" >
<h1>This is the second page</h1>
<div>
<?php echo "Session status: " . session_status(); ?>
</div>
<div>
<?php echo "Name: " . $_SESSION["username"]; ?>
</div>
<div>
<?php echo "Role: " . $_SESSION["pssw"]; ?>
</div>
</div>
</div>
</section>
</body>
What I will expect is that the variables like $_SESSION['name'] will hold any value assigned to them by the PHP file, when the second page is loaded. That way I will be able to set up the display of some elements depending on the login of the user.
Thanks.
SOLVED: I was missing the session_start() in the begining of the mylogin.php file. Thanks to #Robot70 for noticing it.
I got a website in testing, how it works is
Step 1) Form to key in Details in page1.php
Step 2) with the POST function, the keyed in form values appears in next page2.php in read only form format. Sort of like a summary of the information they keyed in. at the bottom they are to click "confirm" and an email is supposed to be sent with the full details of that page2.php.
My problem:
I can get it to sent email from page1.php, in the form page and send email upon clicking submit. but that is not what i want, i want it to send email after they confirm their details from page2.php. there is where i get the error.
my page2.php file has this as the code below. the form-to-email.php is the action to send email which works when its sent directly from a form but not from this page2.php read only page to confirm the details.
What am i doing wrong?
<form action="form-to-email.php" method="post" class="box readonly">
<h3>Vehicle Details</h3>
<div class="f-row">
<div class="one-fourth">Type</div>
<div class="three-fourth">Transport Service</div>
</div>
<div class="f-row">
<div class="one-fourth">Vehicle</div>
<div class="three-fourth">14 Foot Lorry</div>
</div>
<h3>Customer Details</h3>
<div class="f-row">
<div class="one-fourth">Name</div>
<div class="three-fourth"><?php $name = $_POST["name"]; echo $name; ?></div>
</div>
<div class="f-row">
<div class="one-fourth">Phone</div>
<div class="three-fourth"><?php $name = $_POST["number"]; echo $name; ?></div>
</div>
<div class="f-row">
<div class="one-fourth" label for='email'>Email</div>
<div class="three-fourth"><?php $name = $_POST["email"]; echo $name; ?></div>
</div>
<h3>Job Details</h3>
<div class="f-row">
<div class="one-fourth">Date</div>
<div class="three-fourth"><?php $name = $_POST["date"]; echo $name; ?></div>
</div>
<div class="f-row">
<div class="one-fourth">Time</div>
<div class="three-fourth"><?php $name = $_POST["time"]; echo $name; ?></div>
</div>
<div class="f-row">
<div class="one-fourth">Pick Up</div>
<div class="three-fourth"><?php $name = $_POST["pick"]; echo $name; ?></div>
</div>
<div class="f-row">
<div class="one-fourth">Drop Off</div>
<div class="three-fourth"><?php $name = $_POST["drop"]; echo $name; ?></div>
</div>
<div class="f-row">
<div class="one-fourth">Items</div>
<div class="three-fourth"><?php $name = $_POST["items"]; echo $name; ?></div>
</div>
<div class="f-row">
<div class="one-fourth">Remarks</div>
<div class="three-fourth"><?php $name = $_POST["remarks"]; echo $name; ?></div>
</div>
<h3 align="center">TOTAL: $80 SGD</h3><input type="submit" class="btn medium color" value="Confirm (Cash Payment)"></form>
help.
The main problem is that you don't have any inputs in <form> on page2.php. So what you submit is empty.
There are at least 2 ways to solve it:
1 - Store your values in php session:
Add the following lines at top of your page2.php script:
<?php
session_start();
$_SESSION['post_values'] = $_POST;
...
?>
And the following lines at top of your form-to-email.php:
<?php
session_start();
$_POST = $_SESSION['post_values'];
$_SESSION['post_values'] = array(); // this will clear the values, so they wouldn't get resubmitted on page refresh. You could probably use `unset($_SESSION['post_values'])` but that sometimes doesn't work, so it's safer to redefine it as empty array.
...
?>
Storing values in php session will allow you to pass those values to other scripts in same domain. Please note that every time you want to use $_SESSION object, you got to start session first with session_start(). This has to be done before outputting anything.
2 - Add hidden inputs to your code like this (for every field):
<div class="f-row">
<div class="one-fourth">Name</div>
<div class="three-fourth"><input type="hidden" name="name" value="<?php json_encode($_POST["name"]);?>/><?php echo $_POST["name"];?></div>
</div>
<div class="f-row">
<div class="one-fourth">Phone</div>
<div class="three-fourth"><input type="hidden" name="number" value="<?php json_encode($_POST["number"]);?>/><?php echo $_POST["number"];?></div>
</div>
... etc.
That will create invisible inputs so the values could be send again. Please note that I am using json_encode() function so it wouldn't break the HTML syntax if value would contain for example ".
For 2 days I didn't understand why my pictures aren't uploaded onto my server correctly.
I am using osclass and in my theme I have this :
<?php if( osc_price_enabled_at_items() ) { ?>
<div class="control-group">
<label class="control-label" for="price"><?php _e('Recompensa', 'infinity'); ?></label>
<div class="controls">
<?php ItemForm::price_input_text(); ?>
<?php ItemForm::currency_select(); ?> ( optional )
</div>
</div>
<?php } ?>
I was partially able to achieve what I wanted: when someone chooses a category where the price is off, the label with text price disappears, but I still have the problem that my pictures don't upload.
This was my code, but with this the text PRICE is not disappearing, only the text area is:
<?php if( osc_price_enabled_at_items() ) { ?>
<div class="control-group">
<label class="control-label" for="price"><?php _e('Price', 'bender'); ?></label>
<p class="controls">
<?php ItemForm::price_input_text(); ?>
<?php ItemForm::currency_select(); ?> ( optional )
</div></p>
</div>
<?php } ?>
This is the problem
<p class="controls">
should be
<div class="controls">
Unless there is something I'm missing.
i was able to adjust this , was my mistake , the last from my code was in addition i deleted and now is ok , my server uploads pictures with no problem , thank you all