How to make dynamic apps using Phonegap?

  • 2
  • Problem
  • Updated 6 months ago
Hi there, i am a student creating an app. But having some problems, i still cudn't found that what are the plugins and how we can use i used many from list but all they are not responding. Phonegap Team please help me i just want to create an app with camera(to capture images) and Call(to a particular number) how i can use them? I am using build.phonegap.com using dreamweaver. Thanks in advance. I also attached the screen shot of my app
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes

Posted 4 years ago

  • 2
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Sir Petra,
I am using now status bar plugin for ipad.
these configuration I added into config.xml.

.
.
.
<plugin name="cordova-plugin-statusbar"/>
<preference name="StatusBarOverlaysWebView" value="true" />
<preference name="StatusBarStyle" value="lightcontent" />
.
.
.

What should I handle at deviceready event? else
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Nothing. This will do.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Ok Sir thanks
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra,
Why windows build is going failed, did u get some solutions for certificate wrong password issues?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Hi Petra, How are You? I hope you are well.
This is my dashboard, now i am starting Xhttprequest with ajax.

I studied many where, but i am confused which method should i use.
There are plenty of posting option by jquery and ajax.
May be this method is for me?
https://gordoncluster.wordpress.com/2...
want your suggestion Petra.
Thanks in advance.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Yes, you can do it that way. But of course, you need to add both client side and server side input verification.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Of-course not. So for this i should add function in javascript?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
No. It should be implemented server-side
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
-Means in php script?
-Is serverside verification and server side validation are same?
Petra please explain me Sir.
I am already confused
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Saba,
be ready to move to the new forum. This forum will READ ONLY in soon. It may be a week, two weeks or a month, but be ready.

https://forums.adobe.com/community/phonegap

Jesse
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Warm thanks to @Jesse, to inform me. Ok I am ready :)
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
-Means in php script?
Yes, or whatever server side script language you are comfortable with.

-Is serverside verification and server side validation are same?
In this case, yes.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, Please don't be lost in new forum.
Petra, the static map was not showing indoor, when door are opened, but it's working fine at outdoor, instantly :) , all the problems are related to outdoor, so i shouldn't worry.



So, I start with following link:
https://gordoncluster.wordpress.com/2...
I have little confusion.
I have two php files in my project:
1. Config.php

<?Php
///////// Database Details change here ////
$dbhost_name = "localhost";
$database = "amroclean";
$username = "root";
$password = "";
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage();
die();
}
?>

2.Compltype-data.php

<?Php
require "config.php"; // Database Connection

$sql="select compltypeid, description from compltype where active='y' order by description asc ";
$row=$dbo->prepare($sql);
$row->execute();
$result=$row->fetchAll(PDO::FETCH_ASSOC);

echo json_encode(array('data'=>$result));
?>

Now the server input verification, and Insert into query i can add in the Compltype-data.php??????
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Only 4 days ago, you felt insulted when I suggested the same!

- you aren't outdoors (I hope you were smart enough not to test inside a steel building or so)
Petra, i am not small child, i know signals can't be reached in underground or glass and steel :(


Now, about the server side processes: twon months ago, you wrote:
From two years i was learning web designing, i properly knows how to make static websites, and after that i learned how to make dynamic websites using php. I am good also in php+mysql i have made lots of dynamic websites with localhost, and remote/ also.

So, if you're good at that, you should be able to add some simple data validation into your php scripts.
Of course, you should make different interfaces (either within the same web service script or implemented in different single-function scripts) for each functionality to be performed from/to the client.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Only 4 days ago, you felt insulted when I suggested the same!

But Petra, there is a major difference between steel building and without building. As we know that when we are in a under ground building or fully covered building with steel and glass, signals can't be reached. But I didn't know yet that geolocation not works in building even doors and windows are opened.
Still I don't want to more discuss with u, you are my senior and of-course my teacher here.

Now, about the server side processes: twon months ago, you wrote:
From two years i was learning web designing, i properly knows how to make static websites, and after that i learned how to make dynamic websites using php. I am good also in php+mysql i have made lots of dynamic websites with localhost, and remote/ also.

Indeed, but mobile hybrid app, I am developing first time. I am using JQuery Mobile first time, u saw how basic questions I asked to you about JQM. So, I think there is a difference also between mobile hybrid app and dynamic website? I never used ajax Xttp request, Just simple websites with a form and submit in database.
I also know how to validate inputs in php. But when i read that your reply, I am little bit confused.


An example would be consecutive identical complaints, posted within a relatively short timeframe. You don't want such errors to lead to additional mails or database entries towards your customer, do you?


Which type of validation we can apply here? if complaints were posted within a relatively short timeframe?


Petra, Sorry if I did mistake anywhere, forgive me.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You could check if the Complaint comes from the same IP, is of the same complaint type and more or less the same location within the past 30 seconds or so.

What constitutes a duplicate complaint is something you would have to define after talking about it with your client. It would be nothing but a requirement like all others.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Got it, I will work on it, thank you.
Petra, Sorry if I did mistake anywhere, forgive me.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Sir Petra,
I didn't saw ajax xhttp request method in that post.

$.ajax({
type: "POST",
url: url,
data: data,
success: success,
dataType: dataType
});

Is it equivalent to jquery post method?
sorry
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Good Evening Petra,
How are you? I hope you are fine.

Saba
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Fine, thanks.
Is it equivalent to jquery post method?
Yes, it is.
See https://api.jquery.com/jquery.post/
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra,
1. So , which is better for me, it's ajax() or jquery's post method? to post the data into mysql?
2. Should I remove timeout, the third call back of getCurrentPosition NOW, since i know now what were the reason of late fetching gps location.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
1. Whichever you prefer. The post() method is a shorthand for the general ajax() method with a POST attribute.

2. Depends. What do you want to happen if a user gets no GPS fix, for whatever reason?
The fact that you now know one of the reasons why it fails doesn't mean that the user knows, or that there aren't any other possible reasons...
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Thank you Petra, :-) I will pray for u.
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Saba,
Okay. Please post all new questions to the new forum.
https://forums.adobe.com/community/phonegap
Thanks
Jesse
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
@Jesse thanks to inform, but this forum still not read only few questions I can post here too. Also i am few steps far, my app near about to complete.

After all I will create signing keys and certificates.If I will face problems then I will post to new forum.

@saba
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Hi Petra, after 3days m here again :)
How are you there?
Actually Ramadan has been started now.

I am not a single bit free, but still working on app.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Fasting in the month of Ramadhan is obligatory for every Muslim excpet a person is seriuosly ill and can not fast.
In the old times, Muslims have kept on fasting even during wars.We should learn from our ancestors and be that true Muslims.

One more thing, we should remember, when we make an effort for Allah, He helps you.I see my grandparents reaching the age of 70+ and still go to work and fast.They say, Allah gives them strength.And He does.If you put one step forward for Allah, Allah will come 10 steps forward for you.

Islam Never bound someone for any work.
There are five pillars of Islam that are important/necessary.
1)Kalma (means accept by tongue and mind that there is not God but Allah).
2) Salah
3) Fasting
4) Zakat (Donate)
5) Haj (pilgrimage)
The 4,5 fardh only those people can do, which are rich.
-If people are always in hard physical labor during whole year they can replace their missed fastings with certain amount of money or goods(fidyah) which will be distributed to poor people or they can replace it with fasting after iedl fitri when you do not work in hard physical labor.Others said that an old person was free not to observe the fast without fidyah) on the strength of the Quranic verse "On no soul does God place a burden greater than it can bear.

According 2 Islam few ppls are allowed to leave fasting

1- patient with a permanent illness/Disease & due to that he/she can't fast. but if it is temporary illness then he/she must complete remaining days of ramadan.
2- Olds, who are so weak
3- Pregnant/Breast feeding women or women during his monthly period
4- Traveler
5- War
and ofcourse they can fast later in small days and in winters(the due fasts of Ramadan) :)

Do they stay at home instead of going to work?

Some companies grant leaves to their employees for whole month Ramadan, but people/labour who they are poor, they still do their work out.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Thanks for the explanation, Saba.

Just one more question: doesn't this Ramadan fasting have impact on regular life? For instance:
- can kids at school still concentrate when they are awake at night and refrain from eating/drinking at day time?
- what about the team mates of sports teams, if the muslim players can't play? Must matches be cancelled?
- are police forces, fire brigades and medical staff strong enough at day time during Ramadan?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Your welcome always Petra Sir :)
Ofcourse, if you will ask, thousand of questions related to Islam, I will answer them without tired and with lots of interest. :)
1) Muslim children are not required to fast for Ramadan until they reach the age of maturity (puberty). At that time they are responsible for their decisions, and are considered adults in terms of meeting religious obligations. In Many muslims countries there are lots of special programs for only the holy Ramadan, like not test or exam, not extra classes, because teachers also keep fast.
When i was in school, i remember that my school (they allow some leaves too).
If there is something which is necessary or compulsory in Islam, surely it's beneficial for human, It's not muslims saying it's science revising now, which Islam had 1400 years ago).
like:
The effects of Fast on Health
http://english.alarabiya.net/en/life-...

http://image.slidesharecdn.com/shakle...

And during Ramadan we do not awake whole night, It's not necessary, Just for few mins we awake to feed ourself. (And if people awake whole night in Ramadan , they actually know the blessings of Ramadan , they don't want to lose them, they awake whole night, and pray).
2)-However, if you are talking about being allowed not to fast because you play sport (hard work), then it's not allowed, as it wasn't mentioned in Quran that hard works permit not fasting, in truth it was said in the Ayas quoted up there that even if you are allowed not to fast, it's better if you do.
3) Same answer for 3) and 4).



I want to adviceall of muslims (labours, workers, players, any other hard workers against it, no matter how hard the sport we play, it's not as hard as the work Muslims did in Jihad. They were allowed to skip fasting (since they were travelling), but they didn't, so head their way and God will grant us power and help us In sha Allah :)





Want to say onething more:

Allah s.w.t. Examine their Creatures, in different situations, true muslims can proof theirself, and loosers can break their hopes from Allah s.w.t.
-Sometime a poor labor/worker can fast wholeday with workhard. And sometime a rich man deny from fast which lives in AC room altime.
-In my opinion world is exam hall, all we are students, The day of judgement(Qayamat) is result declaration day.
May Allah s.w.t guide us more aameen.

Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
In Many muslims countries there are ...
What is a "muslim country"? Don't you have freedom of religion in your country?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Muslim countries like Arab nations such as Saudi Arabia, Iraq, Oman, United Arab Emirates, Kuwait and non-Arab nations such as Turkey, Northern Cyprus, Iran, and Azerbaijan. South Asia: Afghanistan, Pakistan, Bangladesh and the Maldives. Southeast Asia: Indonesia etc.

Don't you have freedom of religion in your country?

In India 80% ppl are non muslims most of the ppl are HIndus. So muslims are studying in hindus schools, ppl are working in their companies, organizations and others.
Few ppl are working in Islamic organizations, and they are free in Ramdan, they fully celebrate Ramadan, with lots of worship and Zakat(Donation), preparation for EID, like muslim countries.
I want to live in saudi arab for my duniya and akhira, In Shaa Allah.
Oneday I will go there In Shaa Allah.
When I hear about that countries, I wish to live there.
Not in Ramadan, everything is going there according to Islam daily.
There is no scare of things stolen, murder and other crime rates are too low there.
It's look so nice, when Adhan Starts. All cars and buses stops at current place, from one side ladies come out and from other side gentle men comes out from the car, they go to mosque and offer salah.
In malls and in all public places also there is arrangement for salah.
And here we can't see anything like that.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
[from https://c.getsatisfaction.com/nitobi/topics/petra-are-you-there-why-they-suggest-me-different-forum]
what should I do here to show result page?
Well, it depends:

1. If the server returns a JSON object with error information, you show the form again with the fields filled as entered, the error field(s) highlighted and with an error message.
If the server returns an OK (with data?), you want a confirmation, perhaps with data like a complaint number.

2. In case of OK, now it depends on what you want to happen if the user presses the back button from the confirmation page.
(a) If that should be the form again, then parse the server data into sessionStorage, passing them to a next html page and display it.
(b) If it shouldn't, parse the data into place holders of a (so far) hidden div, display that div and hide the form at the same time. Both form and confirmation div are in the same html document.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
1. I am using JSON data for only dynamic pick list. Yes near about i understood, what you are saying.

you want a confirmation, perhaps with data like a complaint number.

Yes, I want confirmation if data posted successfully, with randomly generated complain no.
I used mt_rand(1000000,9999999), function to create 7 digits random number with unique check.
When I filed a complaint. It's posting data successfully with 7 digits random number. I have also sort the problem: (When i was selecting an option regarding complaints from pick list, data was submitting successfully, but when i was not using pick list , i was using other description textfied, data was not inserting. Then i found that complaintypeid is a foreign key complaintype table.) It can't be null. Then I used an extra option "Other" in dynamic pick list. and created a show hide event for other description text field.
2. BTW: On the confirmation page with Thanks i want the current complain no. How I do that?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
BTW: On the confirmation page with Thanks i want the current complain no. How I do that?
You are apparently creating a random Complaint number client side (don't know why, but well, that's how you do it). In that case, you already have the number in the app (it doesn't need to be returned by the server), so you can display it.
Either fit it into the confirmation div at the same html document, or use sessionStorage variables to pass it to a different html document, if that's what you want to use.

Then i found that complaintypeid is a foreign key complaintype table.) It can't be null.
Why can't it be null? You are the one defining the database, aren't you?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra wanna show you my postcomplaints.php script file, i am not creating at client side see:

<?php
$con = mysqli_connect("localhost","root","","amroclean");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$personname=$_POST['personname'];
$emailphn=$_POST['emailphn'];
$locationtxt=$_POST['locationtxt'];
$latlon=$_POST['latlon'];
$complaintlist=$_POST['complaintlist'];
$otherdescription=$_POST['otherdescription'];
$smallImage=$_POST['smallImage'];
$complainno=mt_rand(1000000,9999999);
mysqli_query($con,"INSERT INTO `complaint` (`peresonname`,`emailphn`,`locationtxt`,`compltypeid`,`otherdescription`,`image`,`complainno`) values('$personname','$emailphn','$locationtxt','$complaintlist','$otherdescription','$smallImage','$complainno')");
if($con)
echo "Successfully Inserted";
else
echo "Insertion Failed";
?>

so at the time on new record insertion , number is creating. How i can fetch it from database Instantly after data is posted?

Same like it? I am fetching details of status, by complainno.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "amroclean";

$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$complainno=$_POST['complaintno'];

$sql = "SELECT complainno, peresonname, locationtxt,status FROM complaint where complainno='$complainno'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border=5><tr><th>Complain No.</th><th>Name</th><th>Address</th><th>Your Complaint Status</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["complainno"]. "</td><td>" . $row["peresonname"]. "</td><td>" . $row["locationtxt"]. "</td><td>".$row["status"]."</td></tr>";
}
echo "</table>";
} else {
echo "Sorry, No record found!";
}

$conn->close();
?>



Why can't it be null? You are the one defining the database, aren't you?

Yes I am, but at many ways I tried to post data from form to mysql whenever i didn't select any option from dynamic pick list, rather i used otherdescription option, record was not inserting. When manually i insert from phpmyadmin, by query It was inserting. So I used another option it's also much better than it. see:

<script>
$("#otherdescription").hide();
$( "#complaintlist" ).change(function() {
var val = $("#complaintlist").val();
if($(this).val()=='11'){
$("#otherdescription").show();
} else {
$("#otherdescription").hide();
}
});
</script>

at 11 there is value "Other".
Need for better suggestion Petra Sir/ Thank you sssssssssssssssssssssssooooooo much.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
so at the time on new record insertion , number is creating. How i can fetch it from database Instantly after data is posted?
Why would you? You already have that value in a variable called $complainno<br><br>
at 11 there is value "Other". <br>
Currently perhaps, yes. In your test database. But this is bad design. What if it's not '11' at any time, for instance after a recovery?<br>
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
then what i do friend please help Petru. when i was using value other it's not working, so i used this.value for key/////
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You should change the database attribute for the field, so the foreign key can be null, too. That the basic way how you would implement a 0:n entity relationship
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, I didn't changed database attribute yet.
Want to show u table.
See foreign key is showing null already but when i am querying like this not by form.

INSERT INTO `complaint`(`peresonname`, `emailphn`, `locationtxt`, `otherdescription`) VALUES ('Danish Ali','danishali90@gmail.com','Kailas Road, Amroha','Collected Rubbish')


Still I should do this:

You should change the database attribute for the field, so the foreign key can be null, too. That the basic way how you would implement a 0:n entity relationship

Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, you are saying the database already allows NULL values for the foreign key?
 Great!
What is the real problem, then?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Exactly Sir, but when I am inserting by admin query., but When I am posting data through complaint.html page using postcomplaint.php script, The complaint table is not updating records.
Yes, when i am selecting from pick list, it's inserting rows successfully.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Have you displayed your query in such case, so you can see what's wrong?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
I tried in two ways, one by form and one by query, so when i am posting data by form the records are not updating and when doing query it's updating. :(
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, you need to find out why:
1. Display the data prior to posting and check them
2. Display the data as received by the server and check them
3. Display the generated Insert query and check it. Specifically pay attention to escaping quotes, apostrophs and ampersands
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
1. Display the data prior to posting and check them - Yes I did
2. Display the data as received by the server and check them - - Yes I did
3. Display the generated Insert query and check it. Specifically pay attention to escaping quotes, apostrophs and ampersands - Yes I did
Please see Petra where I am doing mistake, I tried by many ways checked everything. 
When I am skipping dropdown list from form, the records are not updating.
this php script I am using. 

<?php$con = mysqli_connect("localhost","root","","amroclean");

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$personname=$_POST['personname'];
$emailphn=$_POST['emailphn'];
$locationtxt=$_POST['locationtxt'];
$latlon=$_POST['latlon'];
$complaintlist=$_POST['complaintlist'];
$otherdescription=$_POST['otherdescription']; 
$smallImage=$_POST['smallImage'];
$complainno=mt_rand(1000000,9999999);
mysqli_query($con,"INSERT INTO `complaint` (`peresonname`,`emailphn`,`locationtxt`,`complptypeid`,`otherdescription`,`image`,`complainno`) values('$personname','$emailphn','$locationtxt','$complaintlist','$otherdescription','$smallImage','$complainno')");
if($con)
echo "Successfully Inserted";
else
echo "Insertion Failed";
?>


Please?


or


Can't I do like this?

<script>
$('#otherdescription').hide();

val = $('#complaintlist').val();

switch( val ) {

  case "Other":

    $('#otherdescription').hide();

    break;
}
</script>

This script is pretty good for static pick list, but not working for dynamic pick list.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, what exactly is the query when you displayed it in your test?

This script is pretty good for static pick list, but not working for dynamic pick list.
How does it "not work"? And what exactly is the difference between your dynamic pik list and a static pick list? (Once the pick list is generated, the above code doesn't know whether it has been generated from a script or not)
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
<script>  
 $(document).ready(function() {   
$('#complaintlist').change(function(){   
if($('#complaintlist').val() ==='Other')   
   {   
   $('#otherdescription').show();    
   }   
else 
   { 
        $('#otherdescription').hide();    

   }   
});   
});   
</script>
See Petra, this script i used for both: dynamic and static pick list, for static list it's working expected, as scripted. But when I am applying the same script for dynamic pick list. The else statement is working as expected, but when I m choosing the option "Other" it's not showing otherdescription  textarea.
<blockquote>

And what exactly is the difference between your dynamic pik list and a static pick list?

</blockquote>
I dont know but when i used this same script for static list. it;s working as expected.
<script>   
$(document).ready(function() {   
$('#types').change(function(){   
if($('#types').val() === 'Other')   
   {   
   $('#other').show();    
   }   
else 
   {   
   $('#other').hide();      
   }   
});   
});   
</script>   
</head>   
 
<body>   
   
<select id="types" name="types" >   
 <option value="Type 1">Type 1</option>   
 <option value="Type 2">Type 2</option>   
 <option value="Type 3">Type 3</option>   
 <option value="Other">Other</option>   
</select>   
   
<textarea cols=40 rows=5 id="other" name="other" style="display: none;"/></textarea>
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, if
if($('#complaintlist').val() ==='Other')
"doesn't work", then what exactly is the return value of
$('#complaintlist').val()
?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Hi Petra, Good Morning.
$('#complaintlist').val() is returning value 1.

then what i do sir?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, if you choose "Other" in your select list, the value of the select field is "1".
- Have you inspected the generated code for your select list, once jQuery is done with it?
- Can you explain why it returns "1"?
- Can you predict what value will be returned if you click any other option from the generated select box? Could you then test if that prediction was correct?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
So, if you choose "Other" in your select list, the value of the select field is "1".
when I am testing like:
  •  alert($('#complaintlist').val()); It's showing value 1.
  • alert($('#complaintlist').val() ==='Other'); to choose any value from list, showing false
  • alert($('#complaintlist').val() ==='1');, if choosing 'Road and Foothpath' from the list, showing true, else false.
Can you predict what value will be returned if you click any other option from the generated select box? Could you then test if that prediction was correct?
The predicted value is 11, the other option in at value 11, when i am testing like: 
<script>   $(document).ready(function() {   
$('#complaintlist').change(function(){   
if($('#complaintlist').val() ==='11')   
   {   
   $('#otherdescription').show();    
   }   
else 
   { 
        $('#otherdescription').hide();  
   } 
    
});   
});   
</script>
it's working as expected. But it's bad way, coz value can change right?
So What i do now, I tried in many ways but not doing.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Easy.
1. You should not have an option "Other" in your database, since there will not be any record with a vaue of that option. If there is no Complaintype related, the foreign key will be null, anyway.

2. You should add the option "Other" to the pick list in addition to the present real options from the database. In other words: loop through your database results, generate options and then add an option "Other" client-side, with value 'null'.

3. Adjust your script so it detects a value 'null' or any other value and acts accordingly.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
So should I change this vanilla javascript into JQM and add to that post script?
function validateForm() {
var location=document.forms["myForm"]["locationtxt"].value;
//for empty validation
var x=document.forms["myForm"]["personname"].value;
if (x==null || x=="")
 {
  alert("Name must be filled out");
  return false;
 }
var email = document.getElementById('emailphn');
        var mailFormat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})|([7-9]{1}[0-9]{9})+$/;
        if (email.value == "") {
            alert( "  Please enter your Email or Phone Number  ");
        }
        else if (!mailFormat.test(email.value)) {
            alert( "Email Address / Phone number is not valid, Please provide a valid Email or phone number ");
            return false;
        }
       

}
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You need to at least call that function prior to posting data. Also, you need to cancel the post action if an error message is displayed.
Finally, do you really want to alert error messages and not
- a displayed message in the form
- a highlight of the error field(s)
- a placement of the cursor
?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
I want:
- a displayed message in the form
- a highlight of the error field(s)
- a placement of the cursor
but I don't know how I can do that...............
BTW: On successful postinf I want a jqm page with confirmation and with complain no.
Untill user not fill out all required fields and required pattern. I will cancel posting/


But all this script I will use with jqm post method script?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Yes, you need to code that client side, using jQM (well, it can be done without jQM, but since you are using that framework anyway, you should stay there).

Why don't you go step by step?
- error message and cancellation of the post, first
- then error fields highlighting
- then cursor placement
- finally confirmation page

Just take one step at a time. Each step is a very small project.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, I am using ajax call now...see
But problem before validation is: the data is not inserting in table:
what can be reason? U know i was doing it since two days:
But it's not done: My app still not finished.



see this script i am using:
The submit button is not responding anything:

$(document).ready(function() {
 $("#postcomplaint").click(function(){
 var personname=$("#personname").val();
 var emailphn=$("#emailphn").val();
 var locationtxt=$("#locationtxt").val();
 var complaintlist=$("#complaintlist").val();
 var otherdescription=$("#otherdescription").val();
var dataString="title="+personname+"&emailphn="+emailphn+"&location="+locationtxt+"&complaintlist="+complaintlist+"&otherdescription"+otherdescription;
 if($.trim(personname).length>0 & $.trim(emailphn).length>0)
 {
 $.ajax({
 type: "POST",
 url:"postcomplaintinfo.php",
 data: dataString,
 crossDomain: true,
 cache: false,
success: function(data){
 if(data=="ok")
 {
 $('#confirmation').show();
 }
 else if(data=="error")
 {
 alert("error");
 }
 }
 });
 }return false;
 });
 });

this is postcomplaintinfo.php

<?php$con = mysqli_connect("localhost","root","","amroclean");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  if(isset($_POST['postcomplaint']))
 {
$personname=$_POST['personname'];
$emailphn=$_POST['emailphn'];
$locationtxt=$_POST['locationtxt'];
$latlon=$_POST['latlon'];
$complaintlist=$_POST['complaintlist'];
$otherdescription=$_POST['otherdescription']; 
$smallImage=$_POST['smallImage'];
$complainno=mt_rand(1000000,9999999);

mysqli_query($con,"INSERT INTO `complaint` (`peresonname`,`emailphn`,`locationtxt`,`compltypeid`,`otherdescription`,`image`,`complainno`) values('$personname','$emailphn','$locationtxt',$complaintlist,'$otherdescription','$smallImage','$complainno')");
if($con)
echo "ok";
else
echo "error";
 }
?>


Is there something, which is i am forgetting  to add in the script?
Please help Petra, 
Have u any demo app, any hybrid app, from which i can take help, i have to complete it soon sir please.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
1. Are you sure the post call is reached at all?
2. How do you whitelist the php script?
3. How should the app know where the php script is located? You only scripted a local relative url.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, Can't I return the value of PHP variables by $.post method?
and I just used JSON for picklist, then what i do for other fields?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Sure you can use jQuery's .post() method. It receives data back, whatever the server returns.
If the server returns a json object with those variables, then you can receive them in your callback function and display them wherever you need them.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
If someone can control on hunger, he can control on his every wish...
OK, I understand that. But if you have proven to be able to do so once, is it then necessary to prove it every year? Wouldn't it be healthier (and better for your job and school) to do that just once...or if it must be repeated, only every tenth year or so?
Or does Allah need some kind of prove from everyone every year, because he doesn't trust his people?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
OK, I understand that. But if you have proven to be able to do so once, is it then necessary to prove it every year? Wouldn't it be healthier (and better for your job and school) to do that just once...or if it must be repeated, only every tenth year or so?
Petra, There are five pillars of Islam, I mentioned you before, It's not only the  fast, by we can prove we are better muslim, 
Before fast, Salah is listed on number two.
So In a day we offer Salah five times, It's fardh on a Muslims.
So if I offer salah only one day or fast only in a year, I can't fully get the benefits from these worships, Allah does not need our small worships, It's our need. There are lots of Angels who are doing worship for Allah continuously, and they are for always. It's our need we want Him agree with us altime. If I offer salah or do fast for him only one time or only in a year. I can easlily mislead by Shaitaan. 
Salah washes our dirty hearts, it's washes our body, mind, keep us fit, no need to yoga our other exercise if we are offering salah daily, five time in a day. 
And if we are keeping fast every year it's also beneficial for us. Fasting is not only for body and it's biological functions. If someone fasting, then He must fast for his tongue, eyes, mouth, gaze etc, We can't lie, we can't watch forbidden, we can't speak bad, lie, all forbidden deeds we can't do during fast, and it's a good practice for kids, and also youngsters and others.

Also Allah do not force for fast everyone, If someone really can't fast. There are another options for him.

And in life we do not same every year, child, youngsters, old, oldest. Every period of life have different joy of worship. Allah s,w,t likes children's worship, quick accepts their wishes, when we come on the age of young, it's the bad age of man, the most bad deeds age, we do not obey parents. People can easily mislead in this age. And when someone remember His Rab His Allah in this age, Allah like him much. And also of old persons. When they can't stand easily they offer salah by sit and some people by ly on bed. Masha Allah, Allah s,w.t like them much. 

Or does Allah need some kind of prove from everyone every year, because he doesn't trust his people?

Allah do not need anything. He is not  necessitous, rather we all human are his  necessitous. Everything is Allah knows, which is hidden, all secrets of earth and sky. All those things we don't know He knows. 
He know his people, what his people keeps inside their hearts also who is bad who is good, He also turns people heart to the good path. 

Allah no need some kind of proves from everyone. He knows all, all seats are booked in Jannat(heaven) and in (Jahannum) hell for everyone. 

He will judge all at the day of Qiyamah ( The last day of Earth ). Even it's small good deed of small bad deed.

Surely it's our need to do fast, and other worship, it keep us far from bad deeds, it's purify our soul our hearts. 

 because he doesn't trust his people?

See, Mohammad S.A.W (pbuh) , Allah s.w.t loves him more than All. He knew that He will be the most loving, good person in whole world till end. When He was near about to born, Whenever His mom go to take water and other work, clouds go with her. Where she go, A blessful shade go with her. She was far from all pain. Because in her body, Allah s.w.t's  loving person was living. But Allah s.w.t. also test him, also gave Him lots of trials, examine him by many bad conditions. He was hunger but He feed His neighbors, He was beneficial for His friends and also for His enemies, An old woman daily threw rubbish on him. He didn't said anything to her. Once when she did not came to throw rubbish on him. He felt trouble , why she not came today? He asked to people , where she is? someone told Him, she is sick today. He felt bad and quick went her house and asked about her sickness. She cried and accepted Islam. Must read on the google "Who is Mohammad".

Also about His(Mohammad S.A.W) grand sons. Hasan and Hussain. Allah swt. already declared that They are King of Jannat(Heaven), when they born. But you know how they gone from world?

During war, When he was offering salah, their enemy cut their head during sajda. 
They didn't left their Salah at the time of war too. This is the message for all the human being. That do not leave your Salah and also other worships. 

You Know from beginning I ask a question to all, When I came on the bed in night and think that Whole day same routine, finally I came here on bed. What I did today special. ??? I ask to my parents that What is the objective of human being on world. With which mission Allah s,w,t sent us on earth?

People answer many different answers.

But one day i found the answer:


When Allah s.w.t was creating Human one angel came and asked "Ya Allah why you are creating HUMAN, we do worship for you. Then why Human. 

Allah s.w.t replied. You have not stomach, no wishes to control.


I am creating Human with wishes and stomach, I wanna see that when they will busy in World, who one come to me, who will remember me, in his problem, and joy moments, who will remember me in hunger and who will remember in happiness. In busy schedule, who will come for Salah five time in a day. 
And so sad, some muslims do not offer salah five time too in a day. Cry and fall down in sajda when they have problem. When their loving one in a hospital fight with life, But when Allah s.w.t give us happiness we do not remember him :(


And in the last I want to say that I don't know I can find a place in Jannah, Allah s,w,t will reward me oneday or not, I do worship I do fast Because Allah s.w.t is Able for worship. 









 
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Good Morning Petra,
Now it's a working day here, after some holidays due to Eid ul Fitr, I celebrated my Eid very well with your good wishes, thank you :).
I also worked on app during these leaves.
  • Client and server side validation
  • Data return by post method, the complainno, and others.
  • I have two forms in my app, one for post complaint and second to check complaint status.
I did like this:
I wanna show u, if i made some mistakes please acknowledge me:
There is really no one to help me, except you. From long distance you are helping me, by u only I cud did this. Otherwise i can't think i cud create this app. Whole life can't pay your favors. May Allah reward you for this big help.

See: Both html and php files. Although these are working fine, as I espected, but many things I can't see as an ITian. 
Complaints.html
.
.
.
<script>
$(document).ready(function() {
$('#confirmation').hide();
$("#postcomplaint").click(function() {
var personname = $("#personname").val();
var emailphn = $("#emailphn").val();
var locationtxt = $("#locationtxt").val();
var complaintlist = $("#complaintlist").val();
var otherdescription=$("#otherdescription").val();
var image = $("#smallImage").val();
var mailFormat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})|([7-9]{1}[0-9]{9})+$/;
if (personname==null || personname=="")
 {
   $("#nameErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
  return false;
}
if (emailphn== "") {
            $("#emailErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
return false;
        }
if (!mailFormat.test(emailphn)) {
            $("#emailformatErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
return false;
        }
if(locationtxt==null || locationtxt=="")
{
$("#locationErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
return false;
}
if(complaintlist==null || complaintlist=="")
{
$("#complaintlistErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
return false;
}
if(($('#complaintlist option:selected').text()=="Other") && (otherdescription==null || otherdescription==""))
{
$("#otherdescriptionErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
return false;
}

      else
 { 
// Returns successful data submission message when the entered information is stored in database.
$.post("postcomplaintinfo.php", {
personname1: personname,
emailphn1: emailphn,
locationtxt1: locationtxt,
complaintlist1: complaintlist,
otherdescription1:otherdescription,
image1: image
}, function(data) {
$('#page2').hide();
$('#response').html(data);
$('#confirmation').show();

$('#myForm')[0].reset(); 

}).fail(function() {
         
alert( "Posting failed." );
             
});
}
return false;
});
});

 </script>
</body></html>
.
.
.

postcomplaintinfo.php

<?php$con = mysqli_connect("localhost","root","","amroclean");
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$otherdescription2=$smallImage2=$personname2=$emailphn2=$locationtxt2=$complaintlist2="";
$complainno=mt_rand(10000000,99999999);
$nameErr=$emailphnErr=$locationtxtErr=$complaintlistErr=$otherdescriptionErr=$imageErr="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (empty($_POST["personname1"])) {
               $nameErr = "Name is required";
            }else {
               $personname2 =test_input($_POST["personname1"]);
            }
if (empty($_POST["emailphn1"])) {
               $emailphnErr = "Email or Phone is required";
            }else {
               $emailphn2 =test_input($_POST["emailphn1"]);
  // check if e-mail address is well-formed
               if (!filter_var($emailphn2, FILTER_VALIDATE_EMAIL)) {
                  $emailphnErr = "Invalid email format"; 
               }
            }
if (empty($_POST["locationtxt1"])) {
               $locationtxtErr = "Please Enter Location!";
            }
            else {
               $locationtxt2 =test_input($_POST["locationtxt1"]);
            }
if (empty($_POST["complaintlist1"])) {
               $complaintlistErr = "Please Chose Complaint type!";
            }else {
               $complaintlist2 = test_input($_POST["complaintlist1"]);
            } 
if (empty($_POST["otherdescription1"])) {
               $otherdescriptionErr = "Please Specify other complaint type!";
            }else {
               $otherdescription2 = test_input($_POST["otherdescription1"]);
            } 
if (empty($_POST["image1"])) {
               $imagetErr = "Please Select an image!";
            }else {
               $smallImage2 = test_input($_POST["image1"]);
            } 
}
function test_input($data) {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            return $data;
}
mysqli_query($con,"INSERT INTO `complaint` (`peresonname`,`emailphn`,`locationtxt`,`compltypeid`,`otherdescription`,`image`,`complainno`) values('$personname2','$emailphn2','$locationtxt2','$complaintlist2','$otherdescription2','$smallImage2','$complainno')");
if($con)
echo $complainno;
else
echo "Insertion Failed";
mysqli_close($con);
?>

And here is complaintstatus.html
.
.
.
<script>
$(document).ready(function() {
$('#complaintstatus').hide();
$("#checkstatusbtn").click(function() {
var complaintno = $("#complaintno").val();
if (complaintno==null || complaintno=="")
 {
   $("#statusErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
  return false;
}
if (complaintno<=10000000 || complaintno>=99999999) {
            $("#validErr")
       .slideDown("fast",function(){
          $(this).delay(2000).slideUp("fast");
       });
return false;
        }
else
 { 
// Returns successful data submission message when the entered information is stored in database.
$.post("checkstatus.php", {
complaintno: complaintno,
}, function(data) {
$('#page3').hide();
$('#statusresponse').html(data);
$('#complaintstatus').show();

$('#form')[0].reset(); 

}).fail(function() {
         
alert( "An error occured." );
             
});
}
return false;
});
});

 </script>
</body></html>
</body>

</html>
.
.
.

And it's php script file: checkstatus.php

<?php$con= mysqli_connect("localhost","root","","amroclean");
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$complainno=$statusErr="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
            if (empty($_POST["complaintno"])) {
               $statusErr = "Please Enter Complaint Number";
            }else {
               $complainno =test_input($_POST["complaintno"]);
            }
}
function test_input($data) {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            return $data;
}
$sql = "SELECT peresonname, locationtxt, complainno,status FROM complaint where complainno='$complainno'";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
if($row["status"]==0)
   echo "Dear " . $row["peresonname"]. " Your Complaint with Complaint Number " . $row["complainno"]. "is still in progress, thanks for patience"."<br>"."Regards: Nagar Palika, Amroha";
if($row["status"]==1)
echo "Dear " . $row["peresonname"]. " Your Complaint with Complaint Number " . $row["complainno"]. "has been solved"."<br>"."Regards: Nagar Palika, Amroha";
    }}
else {
    echo "Sorry, there is no complaint booked, with this Number, please check the Complaint Number and try again.";
}

mysqli_close($con);
?>
</body>
</html>
When You will check it, I will work on image validation and lat and lon values.