PHP multi-step form with neo4j - php
I am making multi step form for submission of a company information in PHP with neo4j graph database. In first step there is a submission of basic information and in second step , some advanced information for a user to fill.
Then problem is that when I am creating a company node in the first step of the form, it is created successfully but in the next step I am unable to get company id to store Step 2 information of this company. The step 2 form resides in another file.
I am using AJAX form submit method.
I basically need the company name or id that is generated in the first step, in the second step form to store step 2 information of the company.
Adding some code could only be helpful for us.
However, if you what you want to achieve is close to the lastInsertId in PDO/Mysql for e.g., you can achieve it with neo4j too with the RETURN statement that will return you the created node and you can get the id from it, pass it to the second step of your form and retrieve the node with the passed id.
The following code is an example using the PHP Client from Neoxygen https://github.com/neoxygen/neo4j-neoclient :
// Creating your company node
$q = 'CREATE (c:Company {name:"My Awesome Company"}) RETURN c';
$result = $client->sendCypherQuery($q);
$id = $result->getSingleNode()->getId();
Pass now the id to the next step of your form, and load the company from the id :
$id = $_SERVER['POST']['id'];
$q = 'MATCH (c:Company) WHERE id(c) = {company_id} RETURN c';
$params = array('company_id' => $id);
$result = $client->sendCypherQuery($q, $params);
$company = $result->getSingleNode();
// Want to get some info of the node ?
$companyName = $company->getProperty('name');
Hope it helped.
Chris
Related
Pref-fill fields on Gravity Forms
I would like to pre-fill a registration form for 2021 school year using last year's info and send out invitations to all parents. The form all "Allow prefill" turned on for all needed fields. The prefill field name the the 'pf'&the admin name. I tried sending myself an email with a URL containing the prefill fields=last year's data. The obvious problem is security since the link contains personal information. So that won't work. Next I wrote a php function (I initially put the data into an array during development) that will read a csv file on my server that contains the personal information. I installed it into Gravity forms as a plug-in. Unfortunately, I am not familiar enough with php functions so I was unable to filter out extraneous calls to the function. It needs to run only for a specific form ID. In addition, I could not understand the part in the Gravity forms documentation regarding the sub function, so it ran every time I clicked on the web site and bombed the site. My plan was to send an email with an account number and password, and once logged in, the function will run and prefill the fields for that one customer. I would appreciate help either with this function, or a better way to prefill the fields. Thanks for your help. Here's the code: <?php // for testing $account = 'B-613048'; $data_array = Array( Array("pfAccountNumber","B-613001","B-613002","B-613003","B-613004","B-613005","B-613006","B-613007","B-613008","B-613009","B-613010","B-613011","B-613012","B-613013","B-613014","B-613015","B-613016","B-613017","B-613018","B-613019","B-613020","B-613021","B-613022","B-613023","B-613024","B-613025","B-613026","B-613027","B-613028","B-613029","B-613030","B-613031","B-613032","B-613033","B-613034","B-613035","B-613036","B-613037","B-613038","B-613039","B-613040","B-613041","B-613042","B-613043","B-613044","B-613045","B-613046","B-613047","B-613048","B-613049","B-613050","B-613051","B-613052","B-613053","B-613054","B-613055","B-613056","B-613057","B-613058","B-613059","B-613060","B-613061","B-613062","B-613063","B-613064","B-613065","B-613066","B-613067","B-613068","B-613069","B-613070","B-613071","B-613072","B-613073","B-613074","B-613075","B-613076","B-613077","B-613078","B-613079","B-613080"), Array("pfLastYear","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes"), Array("pfPG1Prefix","Mrs.","Ms.","Mrs.","","Mr.","Ms.","Ms.","Mr.","Ms.","Mrs.","Ms.","Mrs.","Mrs.","Ms.","Mrs.","Mrs.","Mrs.","Mrs.","Ms.","Mrs.","Mrs.","Ms.","Mrs.","Mr.","Mrs.","Mrs.","Mrs.","Ms.","Mrs.","Mrs.","Mrs.","","Mrs.","Mrs.","Mrs.","Mrs.","Mrs.","Mrs.","Mrs.","","Mrs.","Mrs.","","Ms.","Mrs.","Mrs.","Ms.","Mr.","Mrs.","Mr.","Mrs.","Ms.","Mr.","Mr.","Mr.","Ms.","Ms.","Dr.","Mrs.","Mrs.","Mr.","Mrs.","Mrs.","Mrs.","","","","","","","","","","","","","","","","") ); $num_rows=count($data_array,0); $num_cols=(count($data_array,1)-$num_rows)/$num_rows; echo "num_rows= ".$num_rows."</br>"; echo "num_cols= ".$num_cols."</br>"; for ($f = 0; $f < $num_cols;$f++){$fields[$f] = $data_array[0][$f];} for($c = 0; $c < $num_cols; $c++) { if($account == $data_array[0][$c]){ for ($r = 0; $r < $num_rows;$r++){ $account_data[$r] = $data_array[$r][$c]; $filter = 'gform_field_value_'.$fields[$r]; add_filter( $filter, 'populate_function' ); function populate_function() { return $account_data[$r]; }; } break; }; } ?> <?php function populate_function($g) { echo "g= ".$g; return $account_data[$g]; }; ?>
I would suggest using the gravity_form function which allows you to pass an array of dynamic population parameter keys with their corresponding values to be populated. Furthermore, if you did not want to require a login prior to accessing the form you could assign a unique ID to each user which would be defined as a URL parameter to identify and retrieve the required field data. For example: www.school.com/signup/?user=unique_complex_user_identier Hits a template with a gravity form URL parameter read and decoded to identify corresponding user, else fail. User data passed into form
Laravel Crud Application Editing a record
I have a problem with my Laravel crud application for Registrations. There are these tables: Registration, ExtraRegistration (with a registration_id, extra_id and extraoptions_id), Extra and ExtraOptions (with the Extra_id). In the RegistrationController when i add a Registration it makes a new record in the ExtraRegistration with the extraoptions_id and the extra_id. the extra_id is the name of the option and the extraoptions_id is the id of the option you selected. But now, when you click on edit a record, it shows all the information. the problem is that when you change the extraoption, it makes another record, and not change the select. And when you have edited something and you look at it again, it still shows the option before you edited it. RegistrationController $options = Extra::where("exa_form_id", $distance->asd_form_id)->get(); foreach($options as $option){ $input_name = "option_" . $option->exa_id; $input_option = $request->$input_name; if(!is_null($input_option)){ $input_name_extra = "extraoptions_" . $option->exa_id; $input_option_extra = $request->$input_name_extra; $registrationextra = new ExtraRegistration(); $registrationextra->iea_registration_id = $registration->isg_id; $registrationextra->iea_extra_id = $input_option; $registrationextra->iea_extraoption_id = $input_option_extra; $registrationextra->iea_price = $option->exa_price; $registrationextra->save(); } } $registration->isg_options = $input_option; $registration->isg_option_extra_id = $input_option_extra; Edit: I want a check before it makes a new ExtraRegistration. that if the price that is in the registration already exists in that registration_id(in ExtraRegistration) it doesnt make another record in the ExtraRegistration. I want to use an if to fix the problem, but not sure where to begin.. Thanks in advance!
It will probably be easier for you if you just use firstOrCreate method that Laravel provides out of the box. You can check it here: https://laravel.com/docs/5.8/eloquent#other-creation-methods That way, you will be able to retrieve the record that you are looking for, if there is any and then perform all the changes on it. If that record doesn't exist, Laravel will create the new record for you which you'll be able to update. I hope this helps!
You are creating new object of ExtraRegistration() so its inserting/creating new record every time. Just changes this line $registrationextra = ExtraRegistration::find($id);//any id to fetch record
Save JSON response from MySQL in Local Storage
I have a problem with my PhoneGap app. I need to get an ID selected by user from index.html to view.html. For example, user choose a link with name on index.html and then press on this link and the view.html page will display an information about "something". With Ajax I make a request to 1.php which returns me a JSON. while($obj = mysqli_fetch_object($result_1)) { $arr[] = $obj;} echo '{"notes":'.json_encode($arr).'}'; The 1.php script return me the next JSON: {"notes":[{"ID":"1000043","text":"Test ","dt":"2015-02-04 20:46:22"},{"ID":"1000037","text":"Here we go AGAIN!!","dt":"2015-02-03 07:42:42"},{"ID":"1000035","text":"Teoriya veroyatnosti - 27 ballov? ","dt":"2015-02-02 19:07:33"},{"ID":"1000032","text":"Test again?!","dt":"2015-01-20 12:48:47"}]} Now if user choose the link with ID-1000043, the app should to display all info about this ID. I try tu use $_SESSION method, but I save only the first ID. After it I try the local storage. My request is: var url="someurl.com/1.php"; $.getJSON(url,function(json){ $.each(json.notes,function(i,info){ var id = []; id = info.ID; localStorage.setItem('test_id',JSON.stringify(id)); On the view.html I have a function which display an ID from local storage... But it also save only the first ID, or an array of IDs'. But my purpose is to get a selected ID and then display an info for user. Update #1. At first attempt I user getItem. It only displays the first ID from MySQL. I use: var store_id = JSON.parse(localStorage["id"]); Thanks in advance.
How do i use a Fabrik (joomla component) form to connect to database table & search for match & return a result?
I am using the Joomla! component Fabrik. The functionality I am trying to get is to have users buy a unique code from my website using e-junkie. On completion of payment, e-junkie will process a script that will send the code to a MySQL database table. After buying, they will then be redirected to a page on the website to activate their code by filling in a form. In order to activate their code, they will need to enter data into three text fields: First Name Last Name Unique Code The form is already set up with Fabrik and displayed nicely on the website. What I need now is when the form is submitted, I need it to connect to the database where the unique codes are stored, search the database table for the matching firstname,lastname and unique code and return a success message if a match is found and a failure message if no match is found. Fabrik allows for PHP plugin scripts to run when the form is submitted, I will use a separate plugin for each field on the form. So far I have come up with the snippet of code below which would be executed when the form is submitted. I am just attempting to validate the firstname field on the form at this stage just to get it working. once it is working i will duplicate the code and adapt it for the other fields (e.g lastname and uniquecode). Problem is i just cant get it to work. It uses Joomla's JFactory/getDBO to connect to the database. My Table name is travelcodes The fields on the form are, firstname, lastname and uniquecode the columns on the table are also firstname,lastname and uniquecode $firstname = '{travelcodes___firstname}'; $value = '{tablename___firstname}'; $db =JFactory::getDBO(); $query=("SELECT firstname FROM travelcodes where field = '$firstname'"); $db->setQuery($query); $response = $db->loadResult(); if ($response == $firstname) { return true; } else { return false; } Any help with this would be much appreciated. Thanks. Bailey
I have no problem using the following setting I think you will need to add JRequest::getVar before ('you_element') and have the setting to be onBeforeProcess $db = JFactory::getDbo(); $date = date("Y-m-d H:i:s", time()); $value = JRequest::getVar('off_line_ap___offline_reason'); $user =& JFactory::getUser(); $uid = $user->id; $db->setQuery("INSERT INTO d2_exchange_log (date_time, part, quantity, user_id, purpose) VALUES ('{$date}', '{$value}', '99','{$uid}', 'Test')"); $submissionsNo=$db->loadResult();
add a name value pair to posted data for joomla to consume and insert into DB
I'm trying to use the Joomla framework to make a create in the main content table.[http://docs.joomla.org/How_to_use_the_JTable_class] This works fine except that some data comes from posted variables and some from logic that happens when a file is uploaded moments before (store the random image name of a jpg) $data=&JRequest::get('post'); this takes a ref to the posted values and I want to add to this Array or Object my field. The code I have makes the new record but the column images, doesnt get my string inserted. I am trying to do something like$data=&JRequest::get('post'); $newdata=(array)$data; array_push($newdata,"images"=>"Dog"); i make newdata as data is a ref to the posted variables and i suspect wont there fore allow me to add values to $data. I'm a flash guy normally not a php and my knowledge is letting me down here. Thanks for any help
Right, first thing: $data=&JRequest::get('post'); $data is an array, you do not have to cast it. To add another element to the array as described in the comments do this: $data['images'] = 'cats'; If you are using normal SQL to do the insert then you would do something like this to get the last inserted id e.g. the id of the row you just inserted: $db = $this->getDBO(); $query = 'Some sql'; $db->setQuery($query); if (!$db->query()) { JError::raiseWarning(100, 'Insert failed - '.$db->getErrorMsg()); } $id = $db->insertid(); If you are developing in Joomla I suggest you use the db functions provided to you rather than mysql_insert_id(); [EDIT] If you want to use store then you can get the last inserted id like so: $row->bind($data); $row->check(); $row->store(); $lastId = $row->id;